To map an array of strings to numbers you can simply use .map(Number). I'm assuming you tried .map(parseInt) (which fails because of the second implied argumetn) but with Number it does work without an additional anonymous function.
Popping the last person to append with an ampersand is pretty clever. Also ES6 string interpolation looks a lot better than concatenating. I probably wouldn't use logic inside them though, instead save it to a var first for readability of the string.
I disagree, eval is only evil when applied on input you don't have full control over.
You define your own operations object which uses only strings you defined, so it's pretty safe. The parseInt on n1 and n2 also makes sure nothing except numbers will come through, so those are safe too.
Either way I wouldn't vote this as best practice, but in this case eval is shorter than a switch and just as safe.
Yeah learn something new.
Thanks :).
Yeahh, mine neither. :)
Note to myself: Never trait written code even as something to start from!
Well this is a bug fixing kata so other solutions aren't exactly following in the spirit of things.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
To map an array of strings to numbers you can simply use .map(Number). I'm assuming you tried .map(parseInt) (which fails because of the second implied argumetn) but with Number it does work without an additional anonymous function.
Popping the last person to append with an ampersand is pretty clever. Also ES6 string interpolation looks a lot better than concatenating. I probably wouldn't use logic inside them though, instead save it to a var first for readability of the string.
I wish there was a 'funny' upvote button for the fatKid var
I disagree, eval is only evil when applied on input you don't have full control over.
You define your own operations object which uses only strings you defined, so it's pretty safe. The parseInt on n1 and n2 also makes sure nothing except numbers will come through, so those are safe too.
Either way I wouldn't vote this as best practice, but in this case eval is shorter than a switch and just as safe.