Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2015 04:21
Show Gist options
  • Save anonymous/f57afbdc2275c4eb6062 to your computer and use it in GitHub Desktop.
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
// 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