-3

I need to return false or alert or console.log('no true') if three list there is not the same number of items?

example
arrOne = [1,2,3];
arrTwo = [5,6,7];
arrTthree = [1,9];

FALSE arrThree has 2 values , one and two have 3 values. If same return true.

wamovec
  • 97
  • 1
  • 2
  • 8

2 Answers2

1

I have similar idea like @geofh, but it need not wrap all your arrays into another one as input.

function compare(...arrays) {
  return arrays.every(arr => arr.length === arrays[0].length);
}

With it, you could invoke compare([1, 2, 3], [5, 6, 7], [1, 9], ...)

Jay
  • 34
  • 4
0

OK, I owe you an answer since I erroneously marked it as duplicate. To generalize, you need a sameLength function that takes an array of arrays, perhaps. That could look like:

function sameLength(arrays) {
    return arrays.slice(1).every(arr => arr.length === arrays[0].length)
}

so sameLength([arr1, arr2, arr3]) would return false in your case.

geofh
  • 535
  • 3
  • 15