Checks if all elements in an array are equal, based on the provided mapping function.
fn
to the first element of arr
.Array.prototype.every()
to check if fn
returns the same value for all elements in the array as it did for the first one.NaN
self-inequality.const allEqualBy = (arr, fn) => {
const eql = fn(arr[0]);
return arr.every(val => fn(val) === eql);
};
allEqualBy([1.1, 1.2, 1.3], Math.round); // true
allEqualBy([1.1, 1.3, 1.6], Math.round); // false
JavaScript, Array
Checks if all elements in an array are unique, based on the provided mapping function.
JavaScript, Array
Creates an array of elements, ungrouping the elements in an array produced by zip and applying the provided function.
JavaScript, Array
Returns the symmetric difference between two arrays, after applying the provided function to each array element of both.