Files
30-seconds-of-code/snippets/allEqual.md
2018-09-25 23:14:42 +03:00

304 B

allEqual

Check if all elements in an array are equal.

Use Array.every() to check if all the elements of the array are the same as the first one.

const allEqual = arr => arr.every(val => val === arr[0]);
allEqual([1, 2, 3, 4, 5, 6]); // false
allEqual([1, 1, 1, 1]); // true