Skip to content

Commit 8882ccf

Browse files
committed
reduce
1 parent 1bb21e2 commit 8882ccf

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

39_array_reduce.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// reduce
2+
// iterates,callback function
3+
// reduces to a single value - number, array, obj
4+
// 1 parameter('acc') - total of all calculations
5+
// 2 parameter ('curr) - current iteration/value
6+
7+
const produk = [
8+
{ name: 'samsung', model: 'android', price: 10000 },
9+
{ name: 'xiaomi', model: 'android', price: 20000 },
10+
{ name: 'iphone', model: 'iphone', price: 30000 },
11+
{ name: 'sony', model: 'android', price: 40000 },
12+
];
13+
14+
let result = produk.reduce(function (acc, current) {
15+
console.log(acc + current.price);
16+
return acc;
17+
});
18+
19+
console.log(result);
20+
21+
// // example method channing
22+
// let result = produk
23+
// .filter(items => items.price > 10000)
24+
// .map(items => items.price * 2)
25+
// .reduce((acc, current) => acc + current);
26+
27+
// console.log(result);

0 commit comments

Comments
 (0)