Created
December 9, 2015 04:21
-
-
Save anonymous/f57afbdc2275c4eb6062 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/fcc0208647c 's solution for Bonfire: 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
// Bonfire: Sum All Numbers in a Range | |
// Author: @fcc0208647c | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sum-all-numbers-in-a-range | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function sumAll(arr) { | |
arr.sort(); | |
start = Math.min.apply(Math, arr); | |
end = Math.max.apply(Math, arr); | |
sum = 0; | |
for (i=start;i<end+1;i++){ | |
console.log(i); | |
sum += i; | |
} | |
return sum; | |
} | |
sumAll([5, 10]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment