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

Is official solution for Computed Property correct? #63

Open
Bushwazi opened this issue Oct 19, 2015 · 1 comment
Open

Is official solution for Computed Property correct? #63

Bushwazi opened this issue Oct 19, 2015 · 1 comment

Comments

@Bushwazi
Copy link

Terminal presents the following as the official solution:
console.log({
[+process.argv[2] % 2 === 0 ? "even" : "odd"]: +process.argv[2],
[+process.argv[2] + +process.argv[3]]: +process.argv[2] + +process.argv[3],
});

When is should be something like (but probably prettier):

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

@ShadowManu
Copy link

Just passing by leaving my two cents: I think the purpose of this exercise is to use Computed Property at its most. The actual official solution is indeed a correct solution, and if you strictly follow the rule of not using temporary variables, its actually a great solution since it doesn't use the var keyword at all.

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