559 B
559 B
title, tags
| title | tags |
|---|---|
| allUnique | array,beginner |
Checks if all elements in an array are equal and returnstrue else returns false.
- Use
Array.prototype.lengthproperty to return the number of elements in that array. - Use
Set()object to collect unique elements from the given array and then theSet.prototype.sizeto get the number of elements in the set - Check the two values for equality
const allUnique = myArray => myArray.length === new Set(myArray).size;
allUnique([1,2,3,4,5]); // true
allUnique([1,1,2,3,4]); // false