I wrote the code to iterate through a given array and then invoke the function subtractTwo on each element. However, when I run the function map the array argument returns unchanged. Does anyone know why this might be?
// create the subtractTwo function, callback function
function subtractTwo (number) {
return number - 2;
}
// create higher-order function, map
function map (array, callback) {
// initiate a for loop, looping through the array and invoking the callback on each element;
for (let i = 0; i < array.length; i ++) {
callback(array[i]);
}
//return the new array
return array;
}
//console.log(subtractTwo(4));
// Uncomment these to check your work!
console.log(typeof subtractTwo); // should log: 'function'
console.log(typeof map); // should log: 'function'
console.log(map([3,4,5], subtractTwo)); // should log: [ 1, 2, 3 ]```