forked from DouglasHdezT/JavaScript_NodeCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample6.js
More file actions
45 lines (35 loc) · 977 Bytes
/
Example6.js
File metadata and controls
45 lines (35 loc) · 977 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
35
36
37
38
39
40
41
42
43
44
45
/**
* Reduce; It reduce the complete array into a single result; it use every element in a formula and the result is joined with an acumulator.
* Returns the acumulator
*/
let books = [
"Cien años de soledad",
"Rayuela",
"El padrino",
"Simbolo perdido",
"El Tunel",
"El retrato de Dorian Grey"
]
let numbers = [1, 2, 3, 4, 5];
let addAllNumbers = () => {
let acumulator = numbers.reduce ((curResult, element) => {
return curResult + element;
},0)
console.log(acumulator);
}
let subAllNumbers = () => {
let acumulator = numbers.reduce ((curResult, element) => {
return curResult - element;
});
console.log(acumulator);
}
let showBookshelf = () => {
let myBookshelf = books.reduce((result, book) =>{
return result + `${book}, `;
}, "My Bookshelf is: ");
myBookshelf = myBookshelf.slice(0, -1);
console.log(myBookshelf);
}
addAllNumbers();
subAllNumbers();
showBookshelf();