Created
August 31, 2021 14:56
-
-
Save tararoutray/04e0f2168fe149be1fb95a0992e27f38 to your computer and use it in GitHub Desktop.
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
// Let's create a function to calculate the sum of all values provided. Values can be indefinite. | |
// args is the name for the array | |
let addAllNumbers = (...args) => { | |
// Initialize the total value with zero. | |
let total = 0; | |
// Loop through each numbers provided and add them | |
for (let number of args) { total += number; } | |
// Return the total value. | |
return total; | |
} | |
console.log(addAllNumbers(1)); // This will output: 1 | |
console.log(addAllNumbers(1, 2, 3)); // This will output: 6 | |
console.log(addAllNumbers(1, 2, 3, 4)); // This will output: 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment