Skip to content

Instantly share code, notes, and snippets.

@minsooshin
Created November 20, 2015 06:15
Show Gist options
  • Save minsooshin/cf9ecf0641c6a6bbb7fd to your computer and use it in GitHub Desktop.
Save minsooshin/cf9ecf0641c6a6bbb7fd to your computer and use it in GitHub Desktop.
// Bonfire: Sum All Numbers in a Range
// Author: @minsooshin
// 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 = [],
min = Math.min(arr[0], arr[1]),
max = Math.max(arr[0], arr[1]);
for(var i = min; i <= max; i++) {
newArr.push(i);
}
return newArr.reduce(function(sum, current) {
return sum + current;
});
}
sumAll([1, 4]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment