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
*/