Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MinSomai/06e60cb717edce4929867411f2a72cfd to your computer and use it in GitHub Desktop.
Save MinSomai/06e60cb717edce4929867411f2a72cfd to your computer and use it in GitHub Desktop.
Intermediate Algorithm Scripting: Sum All Numbers in a RangePassed
function sumAll(arr) {
let sortedArr = arr.sort((a, b)=>a-b);
let sum = sortedArr[0] + sortedArr[1];
for(let i = sortedArr[0]+1; i< sortedArr[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