Write a function named reverseForEach that will be used to extend the Array prototype.
The function should have the same signature as the regular forEach method, but it should iterate the elements in reverse order, from end to beginning.
Array.prototype.reverseForEach = reverseForEach;
const numbers = [1, 2, 3, 4, 5];
numbers.reverseForEach((number, index) => {
console.log(`Index ${index}: ${number}`);
});
/**
* Should print:
* Index 4: 5
* Index 3: 4
* Index 2: 3
* Index 1: 2
* Index 0: 1
*/
Unlock all functions
The first 10 functions are free. Get lifetime access to all 100 with a one-time payment — no subscription.
Upgrade to Pro