underscore.js - Determine if all values in an array of arrays match

javascript, underscore.js

Solution

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`).

Problem

I have an array of arrays, which looks something like this: ``` [["Some string", "Some other string"],["Some third string", "some fourth string"]] ``` I think I can use the `_.all` method in Underscore to determine if all of the arrays match 100% (that is all of their values match), but I'm not sure how to write the required iterator to run the check. Anyone have an idea?

Original source