Skip to content

Commit 6762885

Browse files
Update Sum of Numbers.js
1 parent 844cf69 commit 6762885

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

JavaScript Interview Programs/Sum of Numbers.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ console.log("Sum:", Sum2(4, 5));
3434
// One-liner arrow function to add two numbers
3535
const add = (a, b) => a + b;
3636
console.log(add(3, 2));
37-
// Output:
38-
// 5
37+
// Output: 5
3938

4039
// OR
4140

@@ -90,13 +89,13 @@ let sum2 = 0;
9089
arr2.forEach(num => sum2 += num);
9190
console.log("Addition using forEach (using arrow function):", sum2);
9291
// Output:
93-
// Addition using forEach (using arrow function): 21
92+
// Addition with forEach() (using arrow function): 21
9493

9594
// OR
9695

9796
// forEach() to calculate sum of array elements
9897
let arr3 = [1, 2, 3, 4, 5, 6];
99-
let sum3 = 0;
98+
let sum3 = 0;
10099
// Loop through each element in the array and add it to sum
101100
arr3.forEach(function (num) {
102101
sum3 += num; // sum = sum + num

0 commit comments

Comments
 (0)