i was asked to define a function reduce, that has three parameters, an array, an unknown function, and a number, and reduces the array into a number
and this is was i was given before i was asked to define the function
reduce([1, 2, 3], function(total, number) {
return total + number;
}, 0); // should return 6
I am a bit clueless on what this is asking me to do to be completely honest
if i could at least get some guideline id be grateful
here is my attempt
var reduce = function(array, func, initial){
function func(){
}
for( var i = 0; i < array.length; i++){
func(initial, array[i]);
}
}
Array.prototype.reduceas a static method.