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

Computed Property seems awkward #48

Open
Chrinkus opened this issue Jun 13, 2015 · 1 comment
Open

Computed Property seems awkward #48

Chrinkus opened this issue Jun 13, 2015 · 1 comment

Comments

@Chrinkus
Copy link

This is merely an opinion: having to type out

[+process.argv[3] + +process.argv[2]]: +process.argv[3] + +process.argv[2]

seems far too redundant to be a correct answer.

var obj = {
    [+process.argv[2] % 2 === 0 ? 'even' : 'odd']: +process.argv[2],
    sum: +process.argv[3] + +process.argv[2]
};
console.log(obj);

The above returns something like "{ odd: 21, sum: 24 }" dependent upon provided args.

I really appreciate the method of setting a key based on the number provided as in the even or odd property. Although 'sum:' is not a sexy new ES6 declaration, seeing it side by side with the even or odd result shows how flexible this new tech is.

Otherwise, really enjoying this workshop!

@ShadowManu
Copy link

Remember that a run of the program with the official solution and the same input you loosely mentioned would give the object { "odd": 21, "24":"24 }, so its not exactly the same as the solution you posted (ES6 style or not). True, the code looks clunky and something you wouldn't want to write or look at, but I think the exercise does a good job in its intention: try to write this weird object without using the var keyword. Maybe this could be written as a hint in the problem text to be more clear.

So, this exercise could be done with a scenario with a prettier code solution, but it does prove the point.

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