Created
December 10, 2021 15:24
-
-
Save danielchikaka/cd5420d755d16fd0c90ab7cd74b32777 to your computer and use it in GitHub Desktop.
Unlimited number of parameters summation
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 declaration | |
| |
const sumAllNums = (...args) => { | |
let sum = 0 | |
for (const element of args) { | |
sum += element | |
} | |
return sum | |
} | |
console.log(sumAllNums(1, 2, 3, 4)) // 10 | |
console.log(sumAllNums(10, 20, 13, 40, 10)) // 93 | |
console.log(sumAllNums(15, 20, 30, 25, 10, 33, 40)) // 173 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment