您的位置:首页 > 编程语言 > Ruby

How to sort an array in Ruby to a particular order?

2014-05-24 09:50 597 查看
a=["one", "two", "three"]
b=["two", "one", "three"]

Now I want to sort array 'a' in the order of 'b', i.e
[code]a.sort_by do |element|
b.index(element)
end
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: