如何通过引用变量alpha的每个字母对重音字的数组进行排序。以下代码仅为第一个字母的参考字母,因此我无法获得“ĝusti
”,“ĝusti vin
”,“ĝuspa
”以正确排序。如何在ruby中对重音字的数组进行排序
我需要的代码的话这样的排序:
["bonan matenon", "ĉu vi parolas esperanton","ĝuspa", "ĝusti", "ĝusti vin", "mi amas vin", "pacon"]
def alphabetize(phrases)
alpha = "abcĉdefgĝhĥijĵklmnoprsŝtuŭvz".split(//)
phrases.sort_by { |phrase|
alpha.index(phrase[0])
}
end
alphabetize(["mi amas vin", "bonan matenon", "pacon", "ĉu vi parolas esperanton", "ĝusti", "ĝusti vin","ĝuspa"])
谢谢你这么多。 – hannaminx 2015-02-06 17:16:37
未定义的方法'to_h'为#<枚举器:0x2bcfde8> – peter 2015-02-06 17:20:38
这个作品+1000000 – 2015-07-31 02:30:08