-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem49.js
More file actions
34 lines (23 loc) · 694 Bytes
/
problem49.js
File metadata and controls
34 lines (23 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
You have an array [ 1, 9, 17, 22 ]. Add the all elements
of this array and give output. Do this using `for loop` &
`array.reduce()` method.
problem provider : https://drive.google.com/file/d/1XcvIBe_rJlr6GY2rTnHlbIluTABXNhp7/view
*/
/* ============================
Using for loop
=============================== */
const numbers = [ 1, 9, 17, 22 ];
let total = 0 ;
/* -------Using Normal for loop---------*/
for(var i = 0; i < numbers.length; i++){
const number = numbers[i];
total = total + number;
}
console.log(total);
/* -------Using for of loop---------*/
let total2 = 0 ;
for( const number of numbers){
total2 = total2 + number;
}
console.log(total2);