FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Advanced-Javascript/filter-map-reduce/script.js at master · aul14/Advanced-Javascript · GitHub
aul14
/
Advanced-Javascript
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Advanced-Javascript
/
filter-map-reduce
/
script.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (32 loc) · 1 KB
Breadcrumbs
Advanced-Javascript
/
filter-map-reduce
/
script.js
Copy path
File metadata and controls
39 lines (32 loc) · 1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
const
angka
=
[
-
1
,
8
,
9
,
1
,
4
,
-
5
,
-
4
,
3
,
2
,
9
]
;
// mencari angka >= 3
// menggunakan for
// const newAngka = [];
// for (let i = 0; i < angka.length; i++) {
// if (angka[i] >= 3) {
// newAngka.push(angka[i]);
// }
// }
// console.log(newAngka);
//menggunakan filter 1
// const newAngka = angka.filter(function (a) {
// return a >= 3;
// });
// console.log(newAngka);
// menggunakan filter 2
// const newAngka = angka.filter(a => a >= 3);
// console.log(newAngka);
// menggunakan map, kalikan semua angka dengan 2
// const newAngka = angka.map(a => a * 2);
// console.log(newAngka);
// menggunakan reduce, jumlahkan seluruh elemen pada array
// const newAngka = angka.reduce((accumulator, currentValue) => accumulator + currentValue);
// console.log(newAngka);
// Method chaining
// cari angka > 5
// kalikan 3
// jumlahkan
const
hasil
=
angka
.
filter
(
a
=>
a
>
5
)
.
map
(
a
=>
a
*
3
)
.
reduce
(
(
accumulator
,
currentValue
)
=>
accumulator
+
currentValue
)
;
console
.
log
(
hasil
)
;
Back
|
FazBrowse Home
|
New Git URL