I’ll be surprised if anything is much faster than the obvious way:
a2.sort_by{|x| a1.index x.id}
More Related Contents:
- How to sort an array in Ruby to a particular order?
- how to i add objects to an array ? ruby
- How to sort in-place using the merge sort algorithm?
- Javascript Array.sort implementation?
- How do I pick randomly from an array?
- How to check if a value exists in an array in Ruby
- How to select unique elements
- Ruby array access 2 consecutive(chained) elements at a time
- How to find and return a duplicate value in array
- Array#each vs. Array#map
- Preserve key order (stable sort) when sorting with PHP’s uasort
- What does %w(array) mean?
- Group array by subarray values
- How to split (chunk) a Ruby array into parts of X elements? [duplicate]
- How to count duplicate elements in a Ruby array
- Find indices of elements that match a given condition
- Creating matrix with `Array.new(n, Array.new)`
- Sort hash by key, return hash in Ruby
- Find elements of array one nearest to elements of array two
- Create two-dimensional arrays and access sub-arrays in Ruby
- Is sort in Ruby stable?
- The intersection of two sorted arrays
- Performance of Arrays and Hashes in Ruby
- Ruby method Array#
- In Ruby, why does Array.new(size, object) create an array consisting of multiple references to the same object?
- Ruby – Difference between Array#
- How to sort an array of hashes in ruby
- How to count duplicates in Ruby Arrays
- Regarding in-place merge in an array
- Ruby: filter array by regex?