Skip to content

Latest commit

 

History

History
22 lines (17 loc) · 781 Bytes

allEqual.md

File metadata and controls

22 lines (17 loc) · 781 Bytes
title tags
AllEqual
array,function,beginner

TS JS JS

Check if all elements in an array are equal.

Use Array.prototype.every() to check if all the elements of the array are the same as the first one. Elements in the array are compared using the strict comparison operator, which does not account for NaN self-inequality.

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