Live data from Hacker News

Learn You The Node.js

jamescarl.us

1–8 of 8 posts

Re: Learn You The Node.js

#5
post #2

A far cleaner solution: console.log(process.argv.slice(2).reduce(function(a, x) { return a + parseFloat(x) }, 0));

Why is that cleaner? A for-loop is one of the basic programming constructs.

Re: Learn You The Node.js

#7
post #5
post #2

A far cleaner solution: console.log(process.argv.slice(2).reduce(function(a, x) { return a + parseFloat(x) }, 0));

Why is that cleaner? A for-loop is one of the basic programming constructs.

reduce is one very fundamental construct too https://www.google.com/search?q=universality+of+reduce

Re: Learn You The Node.js

#8
post #5
post #2

A far cleaner solution: console.log(process.argv.slice(2).reduce(function(a, x) { return a + parseFloat(x) }, 0));

Why is that cleaner? A for-loop is one of the basic programming constructs.

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.