Skip to content

Instantly share code, notes, and snippets.

@YanivHaramati
Created January 12, 2015 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YanivHaramati/eb807819c77b6c96d8d8 to your computer and use it in GitHub Desktop.
Save YanivHaramati/eb807819c77b6c96d8d8 to your computer and use it in GitHub Desktop.
adding numbers as a reduce function
// add all numbers from 1 to n
function simpleAdding(n) {
return Array.apply(null, Array(n)).map(function(_, i) {
return i + 1;
})
.reduce(function(p, c) {
return p + c;
}, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment