-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay32.js
More file actions
230 lines (111 loc) · 3.9 KB
/
Day32.js
File metadata and controls
230 lines (111 loc) · 3.9 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//HIGHER ORDER FUNCTIONS[HOF]!
// const sum = [1, 2, 3].reduce((acc, val) => acc + val);
// console.log(sum);
// const evenNumbers = [1, 2, 3, 4].filter((num) => num % 2 === 0);
// console.log(evenNumbers);
// const numbers = [1, 2, 3];
// const total = numbers.reduce((acc, val) => acc + val, 0);
// console.log(total);
// const values = [2, 3, 4];
// const result = values.map(x => x + 1).reduce((a, b) => a * b);
// console.log(result);
// const result = [5, 10, 15].reduce((acc, val) => acc + val, 0);
// console.log(result);
// Problem Statement:
// You are given an array of objects representing products.
// Each product has a name and a price. Write a function processProducts
// that uses map() to create a new array of product names, and then uses forEach()
// to log each product name along with a message indicating whether the price is above or below $50.
// Steps:
// Use map() to extract the product names.
// Use forEach() to iterate over the products and log messages based on the price of each product.
// let Input =
// [
// { name: "aptop", price: 1000 },
// { name: "ouse", price: 20 }
// ]
// let productNames = Input.map((obj)=>obj.name);
// console.log(productNames);
// Input.forEach(function (obj)
// {
// if(obj.price>50)
// {
// console.log(`${obj.name} is above $50`);
// }
// else
// {
// console.log(`${obj.name} is below $50`);
// }
// });
//Problem Statement:
// You are given an array of student objects. Each student object contains a name and marks.
// Write a function processStudents that performs the following steps:
// 1- Filter the students to create a new array of students who scored above 60 marks.
// 2- Sort the filtered array in descending order of marks.
// 3- Map the sorted array to extract only the names of the students.
// 4- Return the array of sorted names.
//INPUT-
// { "name": "Alice", "marks": 58 },
// { "name": "Bob", "marks": 85 },
// { "name": "Charlie", "marks": 92 },
// { "name": "David", "marks": 45 },
// { "name": "Emma", "marks": 76 },
// { "name": "Frank", "marks": 63 },
// { "name": "Grace", "marks": 89 },
// { "name": "Hannah", "marks": 95 },
// { "name": "Ian", "marks": 54 },
// { "name": "Jack", "marks": 79 },
// { "name": "Kate", "marks": 67 },
// { "name": "Leo", "marks": 88 },
// { "name": "Mia", "marks": 91 },
// { "name": "Nathan", "marks": 72 },
// { "name": "Olivia", "marks": 82 }
// ]
//OUTPUT-
// ["Hannah", "Charlie", "Mia", "Grace", "Leo", "Bob", "Olivia", "Jack", "Emma", "Nathan", "Kate", "Frank"]
// let input =
// [
// { "name": "Alice", "marks": 58 },
// { "name": "Bob", "marks": 85 },
// { "name": "Charlie", "marks": 92 },
// { "name": "David", "marks": 45 },
// { "name": "Emma", "marks": 76 },
// { "name": "Frank", "marks": 63 },
// { "name": "Grace", "marks": 89 },
// { "name": "Hannah", "marks": 95 },
// { "name": "Ian", "marks": 54 },
// { "name": "Jack", "marks": 79 },
// { "name": "Kate", "marks": 67 },
// { "name": "Leo", "marks": 88 },
// { "name": "Mia", "marks": 91 },
// { "name": "Nathan", "marks": 72 },
// { "name": "Olivia", "marks": 82 }
// ]
// let filtered = input.filter(function (obj)
// {
// return (obj.marks>60) ;
// })
// console.log(filtered);
// filtered.sort(function (a, b)
// {
// b= b.marks;
// a= a.marks;
// return b-a;
// });
// console.log(filtered);
// let mapped = filtered.map(function(obj)
// {
// return obj.name;
// })
// console.log(mapped);
// let input = ["electronics", "clothing", "electronics", "toys", "clothing", "toys", "toys"];
// let output = input.reduce(function (acc, curr)
// {
// if (acc[curr]) {
// acc[curr] = acc[curr] + 1;
// } else {
// acc[curr] = 1;
// }
// return acc;
// }, {});
// console.log(output);