timoxley / functional-javascript-workshop

A functional javascript workshop. No libraries required (i.e. no underscore), just ES5.
2.06k stars 441 forks source link

Exercise 7:recursion #169

Closed caoxiaoshuai1 closed 7 years ago

caoxiaoshuai1 commented 7 years ago
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.