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

来源:互联网 发布:gcp网络培训 编辑:程序博客网 时间:2024/04/30 09:53

a=["one", "two", "three"]b=["two", "one", "three"]Now I want to sort array 'a' in the order of 'b', i.e
a.sort_by do |element|  b.index(element)end

0 0
原创粉丝点击