-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_pushup.html
More file actions
100 lines (97 loc) · 2.11 KB
/
array_pushup.html
File metadata and controls
100 lines (97 loc) · 2.11 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
var arr = [
{
"title": "Hammer",
"quantity": 25,
"categories": [
"tool"
],
"price": 20
}, {
"title": "Drill",
"quantity": 5,
"categories": [
"tool",
"powered"
],
"price": 100
}, {
"title": "Mower",
"quantity": 5,
"categories": [
"tool",
"gas",
"outdoor"
],
"price": 200
}, {
"title": "Screwdriver",
"quantity": 25,
"categories": [
"tool"
],
"price": 10
}, {
"title": "Computer",
"quantity": 2,
"categories": [
"tool"
],
"price": 699
}, {
"title": "Pencil",
"quantity": 500,
"categories": [
"tool"
],
"price": 1
}, {
"title": "Tesla",
"quantity": 5,
"categories": [
"electric",
"car",
"outdoor"
],
"price": 50000
}, {
"title": "Blue Jeans",
"quantity": 27,
"categories": [
"clothing"
],
"price": 27
}
]
console.log(arr.length);
const highPrice = arr.reduce((acc, cur) => {
console.log(acc, cur, cur.price);
if (acc >= cur.price) return acc;
if (acc < cur.price) return cur.price;
}, 0)
console.log(highPrice);
const highestPriceItem = arr.forEach((ele,i) => {
if (ele.price === highPrice) {
console.log(ele, i);
console.log(arr[i].title);
// return arr[i].title;
return arr[i];
}
} )
console.log(highestPriceItem);
const lowPrice = arr.reduce((acc, cur) => {
console.log(acc, cur, cur.price);
if (acc > cur.price) return cur.price;
if (acc <= cur.price) return acc;
}, arr[0].price)
console.log(lowPrice);
</script>
</body>
</html>