-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice.js
265 lines (205 loc) · 5.33 KB
/
practice.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
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
// const Animal=function(){}
// Animal.prototype.home = function(){
// console.log("Heloooo");
// }
// const Bird = function(){
// }
// Bird.prototype = Object.create(Animal.prototype);
// const bird = new Bird();
// bird.home();
// const allprogress =(promises,onProgress)=>{
// let complete=0;
// return Promise.all(promises.map(promise=>{
// promise.then((result)=>{
// complete++;
// const percent=(complete/promises.length)*100
// onProgress(percent.toFixed(2));
// return result;
// })
// })
// )
// }
// const tasks=[
// ()=>new Promise((resolve)=>setTimeout(()=>resolve("Task1"),2000)),
// ()=>new Promise((resolve)=>setTimeout(()=>resolve("Task1"),7000)),
// ()=>new Promise((resolve)=>setTimeout(()=>resolve("Task1"),9000)),
// ]
// allprogress(tasks.map((t)=>t()),(progress)=>console.log(progress)).then((result)=>console.log(result))
// const allprogress=(promises,onprogress)=>{
// let complete=0;
// return Promise.all(promises.map((promise)=>{
// return promise.then((result)=>{
// complete++;
// const percentage=(complete/promises.length)*100;
// onprogress(percentage.toFixed(2));
// return result;
// })
// }))
// }
// const task=[
// ()=>new Promise(resolve=>setTimeout(()=>{resolve("task1")},2000)),
// ()=>new Promise(resolve=>setTimeout(()=>{resolve("task1")},5000)),
// ()=>new Promise(resolve=>setTimeout(()=>{resolve("task1")},8000)),
// ]
// allprogress(task.map((t)=>t()),(promise)=>console.log(promise)).then((result)=>{
// console.log(result);
// })
// function sum (){
// console.log(typeof sum);
// sum="js"
// console.log(typeof sum);
// }
// sum()
// let a=5;
// let b=8;
// a=a^b;
// b=a^b
// a=a^b
// console.log(a,b);
// generator function
// function* hey(){
// let i=0;
// while(true){
// yield i++
// }
// }
// const generator=hey();
// const a = generator.next().value;
// const b = generator.next().value;
// const c = generator.next().value;
// console.log(a,b,c);
// reversing a string
// function reverseStr(a){
// const arr=a.split("");
// const arr1=arr.reverse();
// const arr2=arr1.join("")
// console.log(arr2);
// }
// reverseStr("12345678")
// var x=1;
// console.log(x);
// function y(){
// console.log("2");
// return 1
// }
// function x(){
// console.log("1");
// return 1
// }
// x() || y()
// smallest number in array
// const arr=[2,43,6,2,76,2455,87,11,42,42,63,3,222,1,23,];
// const compare=(a,b)=>{
// return a-b
// }
// const arr1=arr.sort(compare)
// console.log(arr1[arr1.length-1]);
// const arr=[0,1,2,0,321,0,2,30,3,0,5,7,0];
// const arrZero=arr.filter((x)=>{return x===0;
// })
// const arrnonZero=arr.filter((x)=>{return x!==0;
// })
// console.log(...arrZero,...arrnonZero);
// const arrZero=[]
// const arrNonZero=[]
// const x=()=>{
// for(let i=0;i<arr.length;i++){
// if(arr[i]===0){
// arrZero.push(arr[i]);
// }else{
// arrNonZero.push(arr[i]);
// }
// }
// return [...arrZero,...arrNonZero]
// }
// const newarr=x();
// console.log(newarr);
// array empty index
// js create empty slot,and initialization of these slots not happen. to loop we need indexs which are not created
// const arr=[]
// arr[10]=1;
// arr[20]=5;
// arr[100]=89;
// arr.forEach(x=>{
// console.log("hi");
// })
// console.log(2%5);
// const arr=new Array(2)
// console.log(arr);
// // it creates an empty array and for loop need index thus doen not return any value
// arr.forEach(x=>console.log("😎"))
// but if we destructure it we can get the output
// [...arr].forEach(x=>console.log("😎"))
// console.log(Object.is(NaN,NaN));
// console.log(NaN==NaN);
// console.log(NaN===NaN);
// console.log(NaN==NaN);
// console.log(NaN==NaN);
// const str=`let a=5;
// let b=5;
// console.log(a+b);
// `
// setTimeout(str,2000)
// const a=[1,2,3]
// const b=[1,2,3]
// const c=a
// console.log(a===b)
// console.log(a===c)
// console.log(a==b)
// const a="38"
// console.log()
// const b=Number.parseInt(a)
// console.log(typeof b)
// const array=[32,2130,112,23,13]
// const array1=[0,11,23,89]
// delete array[1]
// console.log(array.concat(array1))
// const arr2=array.sort((a,b)=>{
// return a-b
// })
// const arr2=array.splice(1,-1,11,12)
// const arr2=array.slice(1,3)
// const arr2=array.reverse()
// console.log(arr2)
// console.log(array)
// array.forEach((v,i,a)=>{
// console.log(v,i,a)
// })
// const obj={
// name:"shishimanu",
// loc:"rohtak",
// class:"mca"
// }
// console.log(Object.keys(obj))
// Object.keys(obj).forEach((v)=>{
// console.log(obj[v])
// })
// const arr=["goru","panchal"]
// console.log(arr.toUpperCase())
// let a=" GOU RA V"
// // let b=a.trim().replace(/\s+/g,"")
// console.log(a.includes("O"))
// const sum=(a,b)=>{
// // return a+b;
// console.log(a+b)
// }
// setTimeout(sum,2000,1,99)
// console.log()
// a=1;
// let a;
// console.log(a)
// a=1;
// function sum(a){
// return function(b){
// if(b) return sum(a+b);
// return a;
// }
// }
// const add=sum(23)(3)(565)
// console.log(add())
let a = new Map();
const b = {
name:"goru"
}
a.set(b,"24")
console.log( a)