Created
January 12, 2015 06:06
-
-
Save YanivHaramati/eb807819c77b6c96d8d8 to your computer and use it in GitHub Desktop.
adding numbers as a reduce function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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