Learn You The Node.js
jamescarl.us
Learn You The Node.js
1–8 of 8 posts
Re: Learn You The Node.js
#2A far cleaner solution:
console.log(process.argv.slice(2).reduce(function(a, x) {
return a + parseFloat(x)
}, 0));Re: Learn You The Node.js
#3A far cleaner solution: console.log(process.argv.slice(2).reduce(function(a, x) { return a + parseFloat(x) }, 0));
Awesome! Thanks a ton for the suggestion.
Re: Learn You The Node.js
#4Least bytes?
var a=process.argv,i=a.length,x=0;while(i>2)x-=-a[--i];console.log(x)Re: Learn You The Node.js
#5A 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
#6Least bytes? var a=process.argv,i=a.length,x=0;while(i>2)x-=-a[--i];console.log(x)
That's a neat approach! Thanks
Re: Learn You The Node.js
#7A 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
#8A 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.