Checks if there are duplicate values in a flat array.
Set
to get the unique values in the array.Set.prototype.size
and Array.prototype.length
to check if the count of the unique values is the same as elements in the original array.const hasDuplicates = arr => new Set(arr).size !== arr.length;
hasDuplicates([0, 1, 1, 2]); // true
hasDuplicates([0, 1, 2, 3]); // false
JavaScript, Array
Checks if an array has more than one value matching the given function.
JavaScript, Array
Checks if an array has only one value matching the given function.
JavaScript, Array
Returns the symmetric difference between two arrays, without filtering out duplicate values.