-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay28.js
More file actions
288 lines (241 loc) · 5.49 KB
/
Day28.js
File metadata and controls
288 lines (241 loc) · 5.49 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
//Coding Club Fight!
// function codingClubFight(piyushPower,playersArr,n)
// {
// let count = 0;
// let powerSum = 0;
// let res = '';
// for(let i=0; i<n; i++)
// {
// if(playersArr[i]<=piyushPower)
// {
// count++;
// powerSum+=playersArr[i];
// }
// }
// res+=count;
// res+=' '+powerSum;
// return res;
// }
// function runProgram(input)
// {
// input = input.split('\n');
// let n = +input[0];
// let playersArr = [];
// let line = 1
// for(let i=0; i<n; i++)
// {
// playersArr.push(+input[line++]);
// }
// // console.log(n,nArr);
// let q = +input[line++];
// for(let i=0; i<q; i++)
// {
// let piyushPower = +input[line++];
// let res = codingClubFight(piyushPower,playersArr,n);
// console.log(res);
// }
// }
//Optimise the curve!
// function optimiseTheCurve(A,B,C,K)
// {
// let low = 0;
// let high = K;
// let res = -1;
// while(low<=high)
// {
// let mid = low+Math.floor((high-low)/2);
// let leftSide = (A*(mid*mid)+B*(mid)+C);
// if(leftSide>=K)
// {
// res = mid;
// high = mid-1;
// }
// else
// {
// low = mid+1;
// }
// }
// return res==0?-1:res;
// }
// function runProgram(input)
// {
// input = input.split('\n');
// let tc = +input[0];
// for(let i=0; i<tc; i++)
// {
// let arr = input[i+1].split(' ').map(Number);
// let A = arr[0];
// let B = arr[1];
// let C = arr[2];
// let K = arr[3];
// let res = optimiseTheCurve(A,B,C,K);
// console.log(res);
// }
// }
//Machines At Work!
// function machinesAtWork(targetItems,n,machinesArray)
// {
// let low = 1;
// let high = Math.max(...machinesArray)*targetItems;
// let res = 0;
// while(low<=high)
// {
// let mid = low+Math.floor((high-low)/2);
// let items = 0;
// for(let i=0; i<n; i++)
// {
// items+=parseInt(mid/machinesArray[i]);
// }
// if(items>=targetItems)
// {
// res = mid;
// high = mid-1;
// }
// else
// {
// low = mid+1;
// }
// }
// return res;
// }
// function runProgram(input)
// {
// input = input.split('\n');
// let line1 = input[0].split(' ').map(Number);
// let n = line1[0];
// let targetItems = line1[1];
// let machinesArray = input[1].split(' ').map(Number);
// let res = machinesAtWork(targetItems,n,machinesArray);
// console.log(res);
// }
//Casino And The Dealer!
// function casinoAndTheDealer(k,m,n,tArray)
// {
// let low = 1;
// let high = Math.max(...tArray);
// let res = -1;
// while(low<=high)
// {
// let count = 0;
// let deck = 0;
// let mid = low+Math.floor((high-low)/2);
// for(let i=0; i<n; i++)
// {
// if(tArray[i]<=mid)
// {
// count++;
// if(count==k)
// {
// deck++;
// count = 0;
// }
// }
// else
// {
// count = 0;
// }
// }
// if(deck>=m)
// {
// res = mid;
// high = mid-1;
// }
// else
// {
// low = mid+1;
// }
// }
// return res;
// }
// function runProgram(input)
// {
// input = input.split('\n');
// let tc = +input[0];
// let line = 1;
// for(let i=0; i<tc; i++)
// {
// let line1 = input[line++].split(' ').map(Number);
// let n = line1[0];
// let m = line1[1];
// let k = line1[2];
// let tArray = input[line++].split(' ').map(Number);
// let res = casinoAndTheDealer(k,m,n,tArray);
// console.log(res);
// }
// }
// function sum(a,b)
// {
// return a+b;
// }
// let summ = function (a,b)
// {
// return a+b;
// }
// let arr = [1,2,3,4,5];
// let sumarr = (arr)=>{
// let sum = 0;
// for(let i=0; i<arr.length; i++)
// {
// sum+=arr[i];
// }
// return sum;
// }
// let greetings = (fName, lName)=>`Hey ${fName}, ${lName} Welcome`
// let user = {
// userName: "Bheem",
// userDesignation: "Manager",
// skills: {
// softSkills:['communication','leaderships'],
// techSkills:['js','react','Node.js']
// }
// }
// let {userDesignation, skills, softSkills} = user;
// console.log(userDesignation);
// let a=10;
// let b=20;
// [a,b]=[b,a];
// console.log(a,b);
// let arr1 = [1,2,3,4,5];
// let arr2 = [11,22,33,44,55];
// let fin = [...arr1,...arr2];
// console.log(fin);
// const multiply = (a, b) => {
// return a * b;
// }
// console.log(multiply(2));
// // const { name, age } = null;
// const add = (a, b = 5) => a + b;
// console.log(add(10));
//Problem Statement:-
//Write an arrow function that takes a number as input and returns
// both its square and cube in an object, using implicit return.
// The function should be as concise as possible.
//Requirements:-
// The arrow function should use implicit return (no curly braces or return keyword).
// The function should return an object in the format { square, cube }.
//Example Input:
//5
//Example Output:
//{ square: 25, cube: 125 }
// let sumSquare = (number) => ({Square: number*number, cube: number*number*number})
// console.log(sumSquare(50));
// function counter()
// {
// let count = 0;
// function childCount()
// {
// count++;
// return count;
// }
// return childCount;
// }
// console.log(counter()())
// let arr = ['apple', 'banana', 'kiwi', 'guava'];
// function searchfruit(fruit)
// {
// let res = arr.filter((ele)=>{
// return ele === fruit;
// })
// console.log(res);
// }
// searchfruit('apple');