-
Notifications
You must be signed in to change notification settings - Fork 0
/
loops.js
81 lines (58 loc) · 1.45 KB
/
loops.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
let array1 = [1,2,3,4,5,6,7,8,9];
let array2 = [1,2,2,4,5,6,7,8];
let array3 = [1,2,3,4,5,6,9];
let objArray = [
{
name : "beto",
cash: 200,
},
{
name : "cachito",
cash: 98000,
},
{
name : "tit0",
cash: 9999999.1,
},
]
const sumUpArray = (array) => {
let sum = 0;
for (let i = 0; i < array.length; i++) {
sum += array[i];
}
return sum;
};
document.getElementById('result').innerText = sumUpArray(array1);
const sumUpMap = (array) => {
let sum = 0;
array.map((number) => {
sum += number;
});
return sum;
};
document.getElementById('result2').innerText = sumUpMap(array2);
const sumUpForEach = (array) => {
let sum = 0;
array.forEach((number)=>{
sum += number;
});
};
document.getElementById('result3').innerText = sumUpMap(array3);
const goThruArr = (array) => {
const list = document.getElementById('list');
for (let i = 0; i < array.length; i++) {
let item = document.createElement('li');
item.innerText = array[i].name + " tiene $ " + array[i].cash;
list.appendChild(item);
}
};
goThruArr(objArray);
const goThruMap = (array) => {
array.map((value) => {
let list2 = document.getElementById('list2');
let item = document.createElement('li');
item.innerText = value.name + " tiene tanta platita como " + value.cash;
list2.appendChild(item);
})
};
goThruMap(objArray);