Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ex 7 recursion #184

Open
pdewouters opened this issue Jun 27, 2017 · 1 comment
Open

Ex 7 recursion #184

pdewouters opened this issue Jun 27, 2017 · 1 comment

Comments

@pdewouters
Copy link

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.

@gpetrioli
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants