Skip to content

Instantly share code, notes, and snippets.

@newmanbrad
Last active November 20, 2015 18:43
Show Gist options
  • Save newmanbrad/c4817e493cd30a4aeb22 to your computer and use it in GitHub Desktop.
Save newmanbrad/c4817e493cd30a4aeb22 to your computer and use it in GitHub Desktop.
Sum All Numbers in a Range
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