Skip to content

Instantly share code, notes, and snippets.

@briandailey
Created April 17, 2014 00:05
Show Gist options
  • Save briandailey/10943690 to your computer and use it in GitHub Desktop.
Save briandailey/10943690 to your computer and use it in GitHub Desktop.
learnyounode
// the solution presented
var result = 0
for (var i = 2; i < process.argv.length; i++)
result += Number(process.argv[i])
console.log(result)
// what i wrote
// ignore node and the filename.
var numbers = process.argv.slice(2);
var sum = numbers.reduce(function(previousValue, currentValue, index, array) {
return parseInt(previousValue) + parseInt(currentValue);
});
console.log(sum);
@egdelwonk
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment