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

Improving solution of exercise 11 (Arrow Function) #64

Open
ShadowManu opened this issue Oct 22, 2015 · 0 comments
Open

Improving solution of exercise 11 (Arrow Function) #64

ShadowManu opened this issue Oct 22, 2015 · 0 comments

Comments

@ShadowManu
Copy link

Citing the actual solution in 0.7.0

var inputs = process.argv.slice(2);
    var result = inputs.map((x) => x[0]).reduce((result, x) => result += x);

    console.log(result);

I consider that the equals symbol in the expression result += x is redundant (and maybe even misleading). The first argument to the reduce function is a function that must return the new accumulator... So that expression (when you include the arrow function behavior) is the same as doing result = result + x; return result, making the assignment (not the addition) kinda useless.

P.D: the parenthesis surroinding the x in the map function are optional, but options are ok ;)

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

1 participant