-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path39_array_reduce.js
More file actions
28 lines (23 loc) · 820 Bytes
/
39_array_reduce.js
File metadata and controls
28 lines (23 loc) · 820 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
// reduce
// iterates,callback function
// reduces to a single value - number, array, obj
// 1 parameter('acc') - total of all calculations
// 2 parameter ('curr) - current iteration/value
const produk = [
{ name: 'samsung', model: 'android', price: 10000 },
{ name: 'xiaomi', model: 'android', price: 20000 },
{ name: 'iphone', model: 'iphone', price: 30000 },
{ name: 'sony', model: 'android', price: 40000 },
];
let result = produk.reduce(function (acc, currentItems) {
console.log(`total : ${acc} ${currentItems.price}`);
acc += currentItems.price;
return acc;
}, 100000);
console.log(result);
// // example method channing
// let result = produk
// .filter(items => items.price > 10000)
// .map(items => items.price * 2)
// .reduce((acc, current) => acc + current);
// console.log(result);