Executes a provided function once for each array element, starting from the array's last element.
Array.prototype.slice()
to clone the given array and Array.prototype.reverse()
to reverse it.Array.prototype.forEach()
to iterate over the reversed array.const forEachRight = (arr, callback) =>
arr
.slice()
.reverse()
.forEach(callback);
forEachRight([1, 2, 3, 4], val => console.log(val)); // '4', '3', '2', '1'
JavaScript, Array
Returns every element that exists in any of the two arrays at least once, after applying the provided function to each array element of both.
JavaScript, Array
Finds all unique values of an array, based on a provided comparator function, starting from the right.
JavaScript, Array
Groups the elements into two arrays, depending on the provided function's truthiness for each element.