Last active
November 20, 2015 18:43
-
-
Save newmanbrad/c4817e493cd30a4aeb22 to your computer and use it in GitHub Desktop.
Sum All Numbers in a Range
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
function sumAll(arr) { | |
var sum = 0; | |
var maxNum = Math.max.apply(null, arr); | |
var minNum = Math.min.apply(null, arr); | |
console.log(maxNum); | |
console.log(minNum); | |
for(var i = minNum; i <= maxNum; i++){ | |
sum = parseInt(sum + i); | |
} | |
return sum; | |
} | |
sumAll([1, 4]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment