Skip to content

Commit 7cfb7b6

Browse files
Update Sum of Numbers.js
1 parent 0628d8e commit 7cfb7b6

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

JavaScript Interview Programs/Sum of Numbers.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,23 @@
4747
// Output:
4848
// 5
4949

50-
// 4. Using Rest Parameters ( Used For Multiple Inputs)
51-
function addAll(...nums) {
52-
let sum = 0;
53-
for (let n of nums) {
50+
// 4. Using Rest Parameters (Multiple Inputs)
51+
function addAll(...num) {
52+
let sum = 0;
53+
for (let n of num) {
5454
sum += n;
55-
}
56-
return sum;
55+
}
56+
return sum;
5757
}
5858
console.log(addAll(1, 2, 3, 4));
59-
// Output:
59+
// Output:
6060
// 10
6161

62-
//5. Using prompt() (User Input) – only browser
63-
let arr = [1, 2, 3, 4];
64-
let Sum = arr.reduce((a, b) => a + b, 0);
65-
console.log("Sum:", sum); // Output: 10
62+
63+
// 5. Using reduce() Method (on array)
64+
let arr = [1, 2, 3, 4, 5];
65+
let ADD = arr.reduce((a, b) => a + b, 0);
66+
console.log("Addition:", ADD);
67+
// Output:
68+
// 15
69+

0 commit comments

Comments
 (0)