-
Notifications
You must be signed in to change notification settings - Fork 14
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
Who doesnt have a pair answer #15
base: master
Are you sure you want to change the base?
Who doesnt have a pair answer #15
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This algorithm needs an explanation on why it's working. JSDocs with typings for better writing experience would be great to see as well.
const tmp = [1, 2, 3, 4, 5, 4, 3, 2, 1]; | ||
const tmpAnswer = 5 | ||
|
||
const aloneAtParty = (tmp) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing JSDocs on parameter and return typing
const tmpAnswer = 5 | ||
|
||
const aloneAtParty = (tmp) => { | ||
const a = tmp.reduce((acc, e) => {return acc+e}, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to do {return X}
here. Instead, (acc, e) => acc + e
would be sufficient. Also, we don't know what "a" variable name means.
|
||
const aloneAtParty = (tmp) => { | ||
const a = tmp.reduce((acc, e) => {return acc+e}, 0); | ||
const b = [...new Set(tmp)].reduce((acc, e) => {return acc+e}, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing regarding variable naming and code styling as above.
const aloneAtParty = (tmp) => { | ||
const a = tmp.reduce((acc, e) => {return acc+e}, 0); | ||
const b = [...new Set(tmp)].reduce((acc, e) => {return acc+e}, 0); | ||
return b-(a-b); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a little bit of an explanation comment.
#5 Answer