Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2015 06:29
Show Gist options
  • Select an option

  • Save anonymous/1224165896005955fcd2 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/1224165896005955fcd2 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/patrickcurl 's solution for Bonfire: Sum All Numbers in a Range
// Bonfire: Sum All Numbers in a Range
// Author: @patrickcurl
// 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) {
var newArr = [];
for(var i=Math.min(...arr); i<=Math.max(...arr); i++){
newArr.push(i);
}
total = newArr.reduce(function(a,b){ return a+b; });
return total;
}
sumAll([1, 4]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment