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]
相关文章推荐
- How to format strings in an array in ruby?
- How to sort an NSMutableArray with custom objects in it?
- how to sort array in ruby if i have nil object inside array?
- how to remove nil and blank string in an array in Ruby
- How to find number of a specific integer in an array of Fixnums ruby
- How to Check if an Array Contains a Value in Java Efficiently?
- how to merge array of hash based same keys in ruby?
- How to call different methods as given in an array
- How to get array from string contained identical symbols in Ruby?
- How to Check if an Array Contains a Value in Java Efficiently?---reference
- How to sum values in an array with different hash
- How to get array from string contained identical symbols in Ruby?
- GeeksforGeeks Sort an array according to the order defined by another array
- Converting a array to an array of ranges in ruby
- How to group anagrams in a string into an array
- How to define an array in c#.
- Ruby: Sorting an array of strings, in alphabetical order, that includes some arrays of strings
- Whats the best way to split an array in ruby into multiple smaller arrays of random size
- How to add two multidimensional array in ruby
- How to sort an array by its index? (SortIndex)