Exercise 7:recursion
Closed this issue · 0 comments
caoxiaoshuai1 commented
function reduce(arr, fn, initial){
return (function reduceOne(index, value){
if(index > arr.length - 1) return value
return reduceOne(index+1,fn(value,arr[index],index,arr))
})(0,initial)
}
module.exports = reduce;
What's the code means, I can't understand how it works. Especially for line 4.