Created
July 18, 2015 15:45
-
-
Save alan2207/52d22ea7a541e5604054 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!