0
Ruby的新手和嘗試一些東西。 下面的代碼是將數組轉換爲字符串,同時對數組進行排序並顯示排序後的結果。我掙扎的地方是使用大寫方法來限制所有排序的單詞。簡單的數組排序和大寫
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
我建議排序後資本 – 2014-09-10 13:39:28
謝謝@Santosh&alex提示之後的排序。這很好, **' to_display = the_data.map(&:upcase).sort.join(「\ n」)** – davidt 2014-09-10 13:50:49