Y
Hacker News
new
|
ask
|
show
|
jobs
by
mneary
4526 days ago
A far cleaner solution:
console.log(process.argv.slice(2).reduce(function(a, x) { return a + parseFloat(x) }, 0));
2 comments
jamescarl
4526 days ago
Awesome! Thanks a ton for the suggestion.
link
dsego
4526 days ago
Why is that cleaner? A for-loop is one of the basic programming constructs.
link
mneary
4524 days ago
A for-loop might be a basic programming construct, but it shouldn't be. Mutation and a control flow construct makes for a much worse outlook to the problem than does recursive application of a function.
link
agumonkey
4525 days ago
reduce is one very fundamental construct too
https://www.google.com/search?q=universality+of+reduce
link