Created
April 14, 2020 08:32
-
-
Save alaztetik/48732327d7bc48977b6acca6559353ec to your computer and use it in GitHub Desktop.
sum(range(start, end))
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 range(num1, num2) { | |
const array = []; | |
if (typeof num1 !== 'number' || typeof num2 !== 'number') { | |
throw new Error('Please provide 2 numbers.'); | |
} | |
for (let i = num1; i < num2; i++) { | |
array.push(i); | |
} | |
return array; | |
} |
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 sum(array) { | |
if (typeof array !== 'object') { | |
throw new Error('Please provide an array.'); | |
} | |
let total = 0; | |
for (let i = 0; i < array.length; i++) { | |
total += array[i]; | |
} | |
return total; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment