Skip to content

Instantly share code, notes, and snippets.

@alan2207
Created July 18, 2015 15:45
Show Gist options
  • Save alan2207/52d22ea7a541e5604054 to your computer and use it in GitHub Desktop.
Save alan2207/52d22ea7a541e5604054 to your computer and use it in GitHub Desktop.
function sumAll(arr) {
arr = arr.sort()
var sum = 0
for (var i = arr[0];i<=arr[1];i++){
sum += i
}
return sum
}
sumAll([1, 4]);
@WalterPhillips
Copy link

Instead of sort, use Math.min(...) and Math.max(....) to find out the index of the min and max. And then loop. And then you'll be all set!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment