ruby - Simple array sort and capitalize -


new ruby , trying stuff. code below convert array string while sorting , display sorted results. i'm struggling use of capitalize method caps sorted words.

the_data = ["dog", "cat", "fish", "zebra", "swan", "rabbit", "horse", "albatros", "frog", "mouse", "duck"]  puts "\nthe array:\n" puts the_data puts "\n"  puts "\nthe sorted array, capitalized:\n" to_display =  the_data.sort.join(("\n").capitalize) puts to_display 

you can use array#map capitalize each word of array

to_display =  the_data.sort.map(&:capitalize).join("\n") # => "albatros\ncat\ndog\nduck\nfish\nfrog\nhorse\nmouse\nrabbit\nswan\nzebra" 

if want capitalize letters, can use upcase

to_display =  the_data.sort.map(&:upcase).join("\n") # => "albatros\ncat\ndog\nduck\nfish\nfrog\nhorse\nmouse\nrabbit\nswan\nzebra" 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -