loading
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const animals = [
    {animal: 'zebra', count: 4}, {animal: 'tiger', count: 2},
    {animal: 'lion', count: 3}, {animal: 'turtle', count: 9},
    {animal: 'pig', count: 2},
];

console.log('reduce() example');
const count = animals.reduce((total, curr) => {
    return total += curr.count;
}, 0);

console.log('count =', count, '\n');


console.log('for loop example');
let countAgain = 0;
for (let i=0; i < animals.length; i++) {
    countAgain += animals[i].count;
}

console.log('countAgain =', countAgain);