I have an array of arrays, which looks something like this:
[[\"Some string\", \"Some other string\"],[\"Some third string\", \"some fourth string\"]]
My preference:
_.isEqual(_.sortBy(first), _.sortBy(second))
And if order matters:
_(first).isEqual(second)
Try this guy (order-independent):
function allArraysAlike(arrays) {
return _.all(arrays, function(array) {
return array.length == arrays[0].length && _.difference(array, arrays[0]).length == 0;
});
}
This is assuming you want all of the arrays to contain all the same elements in the same order as one another (so for your example input the function should return false
).
I can't comment on Dan Tao's answer, small change to skip checking of first array against itself (unnecessary _.difference call)
function allArraysAlike(arrays) {
return _.all(arrays, function(array) {
if(array === arrays[0]) return true;
return array.length == arrays[0].length && _.difference(array, arrays[0]).length == 0;
});
}