-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
144 lines (111 loc) · 3.14 KB
/
script.js
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
let games = [
{ name: "Afterparty", price: 125 },
{ name: "Dauntless", price: 100 },
{ name: "The Division 2", price: 200 },
{ name: "Metro Exodus", price: 85 },
{ name: "Tetris 99", price: 20 },
{ name: "Wargroove", price: 50 }
];
let numbersArr = [1, 2, 3, 4, 5];
//reduce
let sumReducer = (accumulator, currentItem) => {
return { price: accumulator.price + currentItem.price };
};
let expensiveReducer = (accumulator, currentItem) => {
return { price: Math.max(accumulator.price, currentItem.price) };
};
// let reduceResult = games.reduce(sumReducer);
// console.log(reduceResult.price);
let reduceResult = games.reduce(expensiveReducer);
// console.log(reduceResult.price);
//some
// let someResult = games.some(item => {
// return item.price < 20;
// });
// console.log(someResult);
//map
// let gamesPrice = games.map(item => {
// return { name: item.name, price: item.price * 2 };
// });
// console.log(gamesPrice);
// //keys, values
// let values = games.values();
// for (let value of values) {
// console.log(value);
// }
//find, findIndex
// let findResult = games.find(item => {
// return item.price < 100;
// });
// let findResult = games.findIndex(item => {
// return item.price == 100;
// });
// console.log(findResult);
//filter
// let filterResult = games.filter(item => {
// return item.price > 80;
// });
// console.log(filterResult);
// //every
// let everyResult = games.every(item => {
// return item.price > 21;
// });
// console.log(everyResult);
// //forEach
// numbersArr.forEach(item => {
// // console.log(item);
// });
// games.forEach(item => {
// console.log(item);
// });
//toString
// console.log(numbersArr.toString());
// //join
// console.log(numbersArr.join("\t"));
//includes
// console.log(numbersArr.includes(2));
// console.log(numbersArr.includes(6));
//concat
// let moreNumbers = [6, 7, 8];
// console.log(numbersArr.concat(moreNumbers));
//reverse
// console.log(numbersArr.reverse());
//sort
// console.log(numbersArr.sort());
//fill(value, start, end)
// console.log(numbersArr.fill(8, 0, 2));
//copywithin(target, start, end)
// console.log(numbersArr.copyWithin(-2));
//slice(begin, end);
// let sliceResult = numbersArr.slice(2, -2);
// console.log(sliceResult);
//splice(start, deleteCount, item1, item2, item3)
// let spliceResult1 = numbersArr.splice(2, 2, 6, 7, 8, 9, 10);
// console.log(spliceResult1);
// console.log(numbersArr);
// //shift
// let shiftResult = numbersArr.shift();
// console.log(shiftResult);
// console.log(numbersArr);
// //unshift
// let unshiftResult = numbersArr.unshift(shiftResult);
// console.log(unshiftResult);
// console.log(numbersArr);
// //push
// let pushResult = numbersArr.push(10);
// // console.log(numbersArr);
// // console.log(pushResult);
// games.push({ name: "Control", price: 250 });
// // console.log(games);
// //pop
// let popResult1 = numbersArr.pop();
// // console.log(popResult1);
// // console.log(numbersArr);
// let popResult2 = games.pop();
// console.log(popResult2);
// console.log(games);
//indexOf
// console.log(numbersArr.indexOf(6));
// console.log(numbersArr[2]);
//length
// console.log(games.length, numbersArr.length);