Created
May 28, 2020 16:54
-
-
Save MinSomai/06e60cb717edce4929867411f2a72cfd to your computer and use it in GitHub Desktop.
Intermediate Algorithm Scripting: Sum All Numbers in a RangePassed
This file contains hidden or 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) { | |
| 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