Answer the question
In order to leave comments, you need to log in
How can two arrays be compared in Ruby if the order is different?
For example, there is an array:
foo1 = [
{name: 'Траволта', age: '15'},
{name: 'Чубайс', age: '50'}
]
foo2 = [
{ name: 'Чубайс', age: '50'},
{name: 'Траволта', age: '15'}
]
Answer the question
In order to leave comments, you need to log in
You have different arrays.
[0, 1] != [1, 0].
Try to compare like this.
foo1.sort_by { |h| h.first } == foo2.sort_by { |h| h.first }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question