Open pdewouters opened 7 years ago
My solution passed, but it is very different from the official solution.
function reduce(arr, fn, initial) { if(!arr.length) return initial; fn(initial, arr[0], 0, arr); return reduce(arr.slice(1), fn, initial); } module.exports = reduce
I'm not really sure I understand more about recursion to be honest. The official solution still looks confusing to me - I wouldn't be able to come up with that myself.
Your solution always passes 0 as the index to the fn. It should be the actual index in the array as the fn might want to use it internally.
0
fn
My solution passed, but it is very different from the official solution.
I'm not really sure I understand more about recursion to be honest. The official solution still looks confusing to me - I wouldn't be able to come up with that myself.