I need to get the user to input five words, which I believe I have. Then the program needs to spit the words in alphabetical order with every other word being in all-caps, s
Here are two ways that don't use indices.
arr = %w|the quicK brown dog jumpEd over the lazy fox|
#=> ["the", "quicK", "brown", "dog", "jumpEd", "over", "the", "lazy", "fox"]
Note:
arr.sort
#=> ["brown", "dog", "fox", "jumpEd", "lazy", "over", "quicK", "the", "the"]
#1
e = [:UC, :LC].cycle
arr.sort.map { |w| (e.next == :UC) ? w.upcase : w.downcase }
# => ["BROWN", "dog", "FOX", "jumped", "LAZY", "over", "QUICK", "the", "THE"]
#2
arr.sort.each_slice(2).flat_map { |u,v| v ? [u.upcase, v.downcase] : [u.upcase] }
# => ["BROWN", "dog", "FOX", "jumped", "LAZY", "over", "QUICK", "the", "THE"]