[–] mneary 12y ago ↗ A far cleaner solution: console.log(process.argv.slice(2).reduce(function(a, x) { return a + parseFloat(x) }, 0)); [–] jamescarl 12y ago ↗ Awesome! Thanks a ton for the suggestion. [–] dsego 12y ago ↗ Why is that cleaner? A for-loop is one of the basic programming constructs. [–] agumonkey 12y ago ↗ reduce is one very fundamental construct too https://www.google.com/search?q=universality+of+reduce [–] mneary 12y 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.
[–] dsego 12y ago ↗ Why is that cleaner? A for-loop is one of the basic programming constructs. [–] agumonkey 12y ago ↗ reduce is one very fundamental construct too https://www.google.com/search?q=universality+of+reduce [–] mneary 12y 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.
[–] agumonkey 12y ago ↗ reduce is one very fundamental construct too https://www.google.com/search?q=universality+of+reduce
[–] mneary 12y 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.
[–] Scryptonite 12y ago ↗ Least bytes? var a=process.argv,i=a.length,x=0;while(i>2)x-=-a[--i];console.log(x) [–] jamescarl 12y ago ↗ That's a neat approach! Thanks
7 comments
[ 3.6 ms ] story [ 25.6 ms ] thread