I created a forEach function that takes an array and a callback function, and runs the callback on each element of the array. The forEach function does not return anything. There is also a separate helper function map that is used.
function forEach(array, callback) {
for (let i = 0; i < array.length; i++) {
callback(array[i]);
}
}
function map(array, callback) {
let newArr = []
forEach(array, newArr.push(callback));
return newArr;
}
console.log(typeof forEach); // should log: 'function'
forEach(['a', 'b', 'c'], i => console.log(i)); // should log: 'a', 'b', 'c'
console.log(typeof map); // should log: 'function'
console.log(map([3, 4, 5], n => n - 2)); // should log: [1, 2, 3]
I get the following error: Type Error on line 4: callback is not a function I'm quite close to resolving the issue but can't seem to figure out how to line 9 with the forEach function call. All test cases above pass, except the very last one.