File tree 3 files changed +69
-20
lines changed
3 files changed +69
-20
lines changed Original file line number Diff line number Diff line change 2
2
3
3
Code snippets with gifs, to avoid copy and paste the code and write it all.
4
4
5
- ## Files for each snippet
6
-
7
- There is a file for each functionality, to be able to execute it.
8
-
9
- Example:
10
-
11
- - File es6/forEach/forEach.js
12
-
13
- - Make it executable:
14
-
15
- ```
16
- chmod +x es6/forEach/forEach.js
17
- ```
18
-
19
- - Run it:
20
-
21
- ```
22
- ./es6/forEach/forEach.js
23
- ```
24
-
25
5
## Table of Contents
26
6
27
7
- [ forEach] ( #forEach )
28
8
9
+ - [ reduce] ( #reduce )
10
+
29
11
## forEach
30
12
31
13
> Example:
@@ -41,3 +23,50 @@ array.forEach((item, index) => {
41
23
> Gif:
42
24
43
25
![ Escribir forEach paso a paso] ( es6/forEach/forEach.gif?raw=true )
26
+
27
+ ## reduce
28
+
29
+ > Example:
30
+
31
+ ``` javascript
32
+ var pilots = [
33
+ {
34
+ id: 10 ,
35
+ name: " Poe Dameron" ,
36
+ years: 14 ,
37
+ },
38
+ {
39
+ id: 41 ,
40
+ name: " Tallissan Lintra" ,
41
+ years: 16 ,
42
+ },
43
+ ];
44
+
45
+ const totalYears = pilots .reduce ((acc , pilot ) => acc + pilot .years , 0 );
46
+ ```
47
+
48
+ > Gif:
49
+
50
+ ![ Escribir forEach paso a paso] ( es6/reduce/reduce.gif?raw=true )
51
+
52
+ > [ Useful use cases] ( https://itnext.io/useful-reduce-use-cases-91a86ee10bcd ) .
53
+
54
+ ## Files for each snippet
55
+
56
+ There is a file for each functionality, to be able to execute it.
57
+
58
+ Example:
59
+
60
+ - File es6/forEach/forEach.js
61
+
62
+ - Make it executable:
63
+
64
+ ```
65
+ chmod +x es6/forEach/forEach.js
66
+ ```
67
+
68
+ - Run it:
69
+
70
+ ```
71
+ ./es6/forEach/forEach.js
72
+ ```
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+
3
+ // From https://medium.com/poka-techblog/simplify-your-javascript-use-map-reduce-and-filter-bd02c593cc2d
4
+
5
+ var pilots = [
6
+ {
7
+ id : 10 ,
8
+ name : "Poe Dameron" ,
9
+ years : 14 ,
10
+ } ,
11
+ {
12
+ id : 41 ,
13
+ name : "Tallissan Lintra" ,
14
+ years : 16 ,
15
+ } ,
16
+ ] ;
17
+
18
+ const totalYears = pilots . reduce ( ( acc , pilot ) => acc + pilot . years , 0 ) ;
19
+ console . log ( { totalYears } ) ;
20
+
You can’t perform that action at this time.
0 commit comments