-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.js
More file actions
974 lines (787 loc) · 23 KB
/
Copy pathtask.js
File metadata and controls
974 lines (787 loc) · 23 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
// === ARRAY MAP ===
// Exercise 1: Double each number in an array
// const numbers=[1,2,3,4,5]
// let num=numbers.map(numbers=>numbers*2)
// console.log(num)
// function numbers(arr){
// let newNum=[]
// for(let i=0;i<arr.length;i++){
// newNum.push(arr[i]*2)
// }
// return newNum
// }
// console.log(numbers([1,2,3,4]))
//-----------------------
// // Exercise 2: Extract property from objects
// const users = [
// { name: 'Ahmed', age: 25 },
// { name: 'Sara', age: 30 },
// { name: 'Mohammed', age: 22 }
// ];
// const names = users.map(user => user.name);
// console.log("Names:", names); // ['Ahmed', 'Sara', 'Mohammed']
// // === ARRAY FILTER ===
// // Exercise 3: Filter even numbers
// const mixedNumbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
// const evenNumbers = mixedNumbers.filter(num => num % 2 === 0);
// console.log("Even numbers:", evenNumbers); // [2, 4, 6, 8, 10]
// // Exercise 4: Filter adults
// const people = [
// { name: 'Ali', age: 17 },
// { name: 'Fatima', age: 25 },
// { name: 'Hassan', age: 14 },
// { name: 'Zahra', age: 30 }
// ];
// const adults = people.filter(person => person.age >= 18);
// console.log("Adults:", adults); // [{ name: 'Fatima', age: 25 }, { name: 'Zahra', age: 30 }]
// // === ARRAY REDUCE ===
// // Exercise 5: Sum all numbers
// const prices = [29.99, 10.50, 5.75, 16.30];
// const total = prices.reduce((sum, price) => sum + price, 0);
// console.log("Total:", total.toFixed(2)); // 62.54
// // Exercise 6: Count occurrences in an array
// const fruits = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple'];
// const fruitCount = fruits.reduce((count, fruit) => {
// count[fruit] = (count[fruit] || 0) + 1;
// return count;
// }, {});
// console.log("Fruit count:", fruitCount); // { apple: 3, banana: 2, orange: 1 }
// // === ARRAY FIND & SOME ===
// // Exercise 7: Find first element meeting condition
// const inventory = [
// { id: 1, item: 'Laptop', inStock: true },
// { id: 2, item: 'Phone', inStock: false },
// { id: 3, item: 'Tablet', inStock: true }
// ];
// const firstInStock = inventory.find(item => item.inStock);
// console.log("First in stock:", firstInStock); // { id: 1, item: 'Laptop', inStock: true }
// // Exercise 8: Check if any student passed
// const students = [
// { name: 'Omar', score: 45 },
// { name: 'Noor', score: 85 },
// { name: 'Yusuf', score: 32 }
// ];
// const anyonePassed = students.some(student => student.score >= 60);
// console.log("Did anyone pass?", anyonePassed); // true
// // === ARRAY FOREACH & EVERY ===
// // Exercise 9: Log each item with index
// const colors = ['red', 'green', 'blue'];
// console.log("Colors with index:");
// colors.forEach((color, index) => {
// console.log(`${index}: ${color}`);
// });
// // Exercise 10: Check if all users are active
// const accounts = [
// { id: 1, active: true },
// { id: 2, active: true },
// { id: 3, active: true }
// ];
// const allActive = accounts.every(account => account.active);
// console.log("All accounts active?", allActive); // true
// // === ARRAY COMBINATION CHALLENGE ===
// // Exercise 11: Chain methods to transform data
// const transactions = [
// { id: 1, amount: 100, type: 'deposit' },
// { id: 2, amount: 50, type: 'withdrawal' },
// { id: 3, amount: 200, type: 'deposit' },
// { id: 4, amount: 25, type: 'withdrawal' }
// ];
// const totalDeposits = transactions
// .filter(t => t.type === 'deposit')
// .map(t => t.amount)
// .reduce((sum, amount) => sum + amount, 0);
// console.log("Total deposits:", totalDeposits); // 300
// //
// const Array=[1,22,3]
// consol.log(typeof(Array))
// tr.split(" ")
//remove all
// let array=[1,2,3,4,5,6]
// console.log(array.filter(arr=>arr.null))
// //array to object conversion
// const key =['id','name','email','role'];
// const values =[101,'rheem','rheem@example.com','developer']
// const obj = key.reduce((acc, curr,id) => {
// acc[curr] = values[id];
// return acc;
// }, {});
// //task 2
// obj.permstion=['read','write']
// console.log(obj);
// //task 3 =
// const reobj = Object.keys(obj)
// console.log(reobj);
// function validations(str){
// let vowels ='aieoAIEO'
// let digit = '1234567890';
// let allchar = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM';
// for (let i=0;i<str.length;i++){
// if(str.length <3){
// return false
// }
// else if(vowels.includes(str[i])){
// return false
// }
// else if(str.includes(digit) && str.includes(allchar)){
// return true
// }
// }}
// console.log(validations("rheem"));
// console.log(validations("ali22"));
// console.log(validations("wdbiaABFAE123"));
// console.log(validations("@$"));
// //the sumation equals the target
// let num = [1,2, 4, 5, 7], target = 8;
// for (let i = 0; i < num.length; i++) {
// for (let j = i + 1; j < num.length; j++) {
// if (num[i] + num[j] === target) {
// console.log(num[i],num[j]);
// }
// }
// }
//================================
// //remove duplicate using map
// const name1 =['ahmed','ali','rheem','ahmed','ali','ahmed']
// let d = name1.map((item, index) => {
// return name1.indexOf(item) === index ? item : null;
// }).filter(item => item !== null);
// console.log(d)
//--------------------------
// sum content
// function sumArray(arr) {
// let sum = 0
// for (let i = 0; i < arr.length; i++) {
// sum += arr[i]
// }
// return sum
// }
// console.log(sumArray([1,2,3,4]))
//----------------------------
// function find(arr) {
// let maxnum = arr[0]
// for (let i = 1; i < arr.length; i++) {
// if (arr[i] > maxnum) {
// maxnum = arr[i]
// }
// }
// return maxnum
// }
// console.log(find([1,2,3,5,0,6]))
//-----------------------------------
//---------------THURSDAY-------------
// //wordFrecuency عدد تكرار الكلمات
// function wordFrecurncy(str){
// let a = {}
// let splitstr =str.split(" ")
// // console.log(i)
// for(let i of splitstr){
// a[i] = (a[i] || 0) + 1
// }
// return a
// }
// console.log(wordFrecurncy("the full stack is a7a a7a"))
//Q2- function named a groupByAgeRange 1-17,18-25,26-40
// let a =[
// {name:"ahmed",age:12},
// {name:"ali" ,age:19},
// {name :"rheem" ,age: 34}
// ]
// function groupByAgeRange(a) {
// let ageGroup = {
// "1-17":[],
// "18-25":[],
// "26-40": []
// };
// for (let i of a) {
// if (i.age < 18) {
// ageGroup["1-17"].push(i.name)
// }else if(i.age>17 && i.age<26){
// ageGroup["18-25"].push(i.name)
// }
// else if(i.age>26 && i.age<=40){
// ageGroup["26-40"].push(i.name)
// }
// }
// return ageGroup;
// }
// console.log(groupByAgeRange(a))
//remove all
// let array=[1,2,3,4,5,6]
// console.log(array.filter(arr=>arr.null))
//sum of element of array using reduse
// let array=[1,2,3,4,5,6]
// let sum = array.reduce((a,b) => a+b, 2);
// console.log(sum)
//---------------
//reverse without reduse
// let array=[1,2,3,4,5,6]
// for(let i=array.length-1;i>=0;i--){
// array.push(array[i])
// }
// array.splice(0,array.length/2)
// console.log(array)
// // ✅ Q5: Create an object "student" with keys: name, grade, subjects (an array).
// let student = {
// name: "Ali",
// grade: 50,
// grade1:40,
// subjects: ["Math", "English", "Science"]
// };
// // ✅ Q6: Add a new key "passed" with value true if grade is above 60.
// if(student.grade>60){
// student.passed=true}
// else{
// student.passed=false
// }
// //console.log(student)
// // ✅ Q7: Loop through the object and print each key and its value in this format: "key: value"
// for(let i in student){
// console.log(i,':',student[i])
// };
// // for(let key in student){
// // console.log(`${key}:${student[key]}`);
// // }
// // ✅ Q8: Add a method inside the object that prints the student's full info.
// student.printInfo=function(){
// console.log(`"the name:"${this.name}`,this.grade,this.subjects,this.passed)
// }
// student.printInfo()
// //q9:sum two ferade from an object
// student.sum=function(grade,grade1){
// console.log(grade+grade1)
// }
// student.sum(student.grade,student.grade1)
//-----------------------------
// array of object i want swap the colors of car use items of array
// let cars = [
// { name :'bmw',color:'red'},
// { name :'bently',color:'blue'}
// ];
// cars.map((item) => {
// if (item.name === 'bmw') {
// item.color = 'blue';
// } else if (item.name === 'bently') {
// item.color = 'red';
// }
// });
// console.log(cars);
//
//i want create
//array to object conversion
// const key =['id','name','email','role'];
// const values =[101,'rheem','rheem@example.com','developer']
// const obj = key.reduce((acc, curr,id) => {
// acc[curr] = values[id];
// return acc;
// }, {});
// //task 2
// obj.permstion=['read','write']
// console.log(obj);
// //task 3 =
// const reobj = Object.keys(obj)
// console.log(reobj);
//=============
// //it contains at least three numbers
// //it contains only digit 0-9 and all english letter
// function validations(str) {
// let digitCount = 0;
// let onlyDigitsAndLetters = true;
// for (let i = 0; i < str.length; i++) {
// const char = str[i];
// if (char >= '0' && char <= '9') {
// digitCount++;
// } else if (
// !(char >= 'a' && char <= 'z') &&
// !(char >= 'A' && char <= 'Z')
// ) {
// onlyDigitsAndLetters = false;
// break;
// }
// }
// if (digitCount >= 3 && onlyDigitsAndLetters) {
// return true;
// } else {
// return false;
// }
// }
// console.log(validations("hellnah"));
//
//=====================
// //remove duplicate using map
// const name1 =['ahmed','ali','rheem','ahmed','ali','ahmed']
// let d = name1.map((item, index) => {
// return name1.indexOf(item) === index ? item : null;
// }).filter(item => item !== null);
// console.log(d)
//--------------------------
// sum content
// function sumArray(arr) {
// let sum = 0
// for (let i = 0; i < arr.length; i++) {
// sum += arr[i]
// }
// return sum
// }
// console.log(sumArray([1,2,3,4]))
//----------------------------
// function find(arr) {
// let maxnum = arr[0]
// for (let i = 1; i < arr.length; i++) {
// if (arr[i] > maxnum) {
// maxnum = arr[i]
// }
// }
// return maxnum
// }
// console.log(find([1,2,3,5,0,6]))
//-----------------------------------
//---------------THURSDAY-------------
// //wordFrecuency عدد تكرار الكلمات
// function wordFrecurncy(str){
// let a = {}
// let splitstr =str.split(" ")
// // console.log(i)
// for(let i of splitstr){
// a[i] = (a[i] || 0) + 1
// }
// return a
// }
// console.log(wordFrecurncy("the full stack is a7a a7a"))
//Q2- function named a groupByAgeRange 1-17,18-25,26-40
// let a =[
// {name:"ahmed",age:12},
// {name:"ali" ,age:19},
// {name :"rheem" ,age: 34}
// ]
// function groupByAgeRange(a) {
// let ageGroup = {
// "1-17":[],
// "18-25":[],
// "26-40": []
// };
// for (let i of a) {
// if (i.age < 18) {
// ageGroup["1-17"].push(i.name)
// }else if(i.age>17 && i.age<26){
// ageGroup["18-25"].push(i.name)
// }
// else if(i.age>26 && i.age<=40){
// ageGroup["26-40"].push(i.name)
// }
// }
// return ageGroup;
// }
// console.log(groupByAgeRange(a))
//remove all
// let array=[1,2,3,4,5,6]
// console.log(array.filter(arr=>arr.null))
//sum of element of array using reduse
// let array=[1,2,3,4,5,6]
// let sum = array.reduce((a,b) => a+b, 2);
// console.log(sum)
//---------------
//reverse without reduse
// let array=[1,2,3,4,5,6]
// for(let i=array.length-1;i>=0;i--){
// array.push(array[i])
// }
// array.splice(0,array.length/2)
// console.log(array)
// // ✅ Q5: Create an object "student" with keys: name, grade, subjects (an array).
// let student = {
// name: "Ali",
// grade: 50,
// grade1:40,
// subjects: ["Math", "English", "Science"]
// };
// // ✅ Q6: Add a new key "passed" with value true if grade is above 60.
// if(student.grade>60){
// student.passed=true}
// else{
// student.passed=false
// }
// //console.log(student)
// // ✅ Q7: Loop through the object and print each key and its value in this format: "key: value"
// for(let i in student){
// console.log(i,':',student[i])
// };
// // for(let key in student){
// // console.log(`${key}:${student[key]}`);
// // }
// // ✅ Q8: Add a method inside the object that prints the student's full info.
// student.printInfo=function(){
// console.log(`"the name:"${this.name}`,this.grade,this.subjects,this.passed)
// }
// student.printInfo()
// //q9:sum two ferade from an object
// student.sum=function(grade,grade1){
// console.log(grade+grade1)
// }
// student.sum(student.grade,student.grade1)
//-----------------------------
// array of object i want swap the colors of car use items of array
// let cars = [
// { name :'bmw',color:'red'},
// { name :'bently',color:'blue'}
// ];
// cars.map((item) => {
// if (item.name === 'bmw') {
// item.color = 'blue';
// } else if (item.name === 'bently') {
// item.color = 'red';
// }
// });
// console.log(cars);
//
//i want create
//array to object conversion
// const key =['id','name','email','role'];
// const values =[101,'rheem','rheem@example.com','developer']
// const obj = key.reduce((acc, curr,id) => {
// acc[curr] = values[id];
// return acc;
// }, {});
// //task 2
// obj.permstion=['read','write']
// console.log(obj);
// //task 3 =
// const reobj = Object.keys(obj)
// console.log(reobj);
//=============
// //it contains at least three numbers
// //it contains only digit 0-9 and all english letter
// function validations(str) {
// let digitCount = 0;
// let onlyDigitsAndLetters = true;
// for (let i = 0; i < str.length; i++) {
// const char = str[i];
// if (char >= '0' && char <= '9') {
// digitCount++;
// } else if (
// !(char >= 'a' && char <= 'z') &&
// !(char >= 'A' && char <= 'Z')
// ) {
// onlyDigitsAndLetters = false;
// break;
// }
// }
// if (digitCount >= 3 && onlyDigitsAndLetters) {
// return true;
// } else {
// return false;
// }
// }
// console.log(validations("hellnah"));
//======================
//return the index who is the right side equels left side (sumaation i mean )
// let array = [1, 7, 3, 6, 5, 6];
// for (let i = 0; i < array.length; i++) {
// let leftSum = 0;
// let rightSum = 0;
// for (let j = 0; j < i; j++) {
// leftSum += array[j];
// }
// for (let j = i + 1; j < array.length; j++) {
// rightSum += array[j];
// }
// if (leftSum === rightSum) {
// console.log(array[i]);
// }
// }
//=====================================
// //prient integer mount value true else false if a mountain arr reture true
// let arr = [1, 2, 4, 3, 5, 3, 2];
// let peak = Math.max(...arr);
// let peakIndex = arr.indexOf(peak);
// let isMountain = true;
// for (let i = 0; i < peakIndex; i++) {
// if (arr[i] >= arr[i + 1]) {
// isMountain = false;
// break;
// }
// }
// if (isMountain) {
// for (let i = peakIndex; i < arr.length - 1; i++) {
// if (arr[i] <= arr[i + 1]) {
// isMountain = false;
// break;
// }
// }
// }
// console.log("Peak:", peak);
// console.log("Is Mountain Array?", isMountain);
//=======================
////check if its valley or not
// let arr = [9, 7, 4, 2, 3, 5, 8];
// let lowest = Math.min(...arr);
// let lowestIndex = arr.indexOf(lowest);
// let isValley = true;
// for (let i = 0; i <= lowestIndex; i++) {
// if (arr[i] <= arr[i + 1]) {
// isValley = false;
// break;
// }
// }
// if (isValley) {
// for (let i = lowestIndex ; i < arr.length - 1; i++) {
// if (arr[i] >= arr[i + 1]) {
// isValley = false;
// break;
// }
// }
// }
// console.log(lowest);
// console.log("Is Valley :", isValley);
//=======================
// Binary search in a sorted array (easier version, using for loop)
// let num = [1, 2, 4, 5, 7], target = 5;
// let index = -1;
// for (let left = 0, right = num.length - 1; left <= right;) {
// let mid = Math.floor((left + right) / 2);
// if (num[mid] === target) {
// index = mid;
// break;
// }
// if (num[mid] < target) {
// left = mid + 1;
// } else {
// right = mid - 1;
// }
// }
// console.log(index);
//====================
// let num = [1,2, 5,4, 7], target = 5;
// for (let i = 0; i < num.length; i++) {
// if (num[i] === target) {
// console.log(i);
// break;
// }
// else if (num[i] > target) {
// console.log(i);
// break;
// }
// }
// //every zero put it in the last in same array use push dont use another array solve it using binary search
// let arr = [0, 1, 0, 3, 5];
// let j = 0;
// for (let i = 0; i < arr.length; i++) {
// if (arr[i] !== 0) {
// let temp = arr[i];
// arr[i] = arr[j];
// arr[j] = temp;
// j++;
// }
// }
// console.log(arr)
//==================
// //function compaire string between two
// let s="tnagram", t="nagaram";
// function check(){
// if(s.length !== t.length) return false;
// let a = {};
// for(let i of s) {
// a[i] = (a[i] || 0) +1
// }
// for(let j of t){
// if(!a[j]) return false
// a[j]--;
// }
// return true;
// }
// console.log(check())
//================================
// // return the index of target
// function suma(num,target){
// for (let i = 0; i < num.length; i++) {
// for (let j = i + 1; j < num.length; j++) {
// if (num[i] + num[j] === target) {
// return [i,j]
// }
// }
// }}
// console.log(suma([2,7,6,8],9))
//=======================
// // Intersection of Two Arrays
// let nums1 = [1, 2, 5, 3];
// let nums2 = [0, 2, 3, 6];
// let arr=[]
// for(let i=0;i<nums1.length;i++){
// for(let j=0 ;j<=nums2.length;j++){
// if(nums1[i]===nums2[j]){
// arr.push(nums1[i])
// break;
// }
// }
// }
// console.log(arr)
//====================
// //expected output:[[-1, -1, 2], [-1, 0, 1]]
// nums = [-1, 0, 1, 2, -1, -4]
// function resultt(array){
// let output=[]
// for(let i=0;i<array.length-2;i++){
// for(let j=i+1;j<array.length-1;j++){
// for(let v=j+1;v<array.length;v++)
// if(array[i]+array[j]+array[v]==0){
// output.push([array[i],array[j],array[v]])
// }
// }
// }
// return output;
// }
// console.log(resultt(nums))
//=====================
// let arr=[1,2,3,4,5,6]
// function sumArr(arr){
// let sum=0
// for(let i=0;i<arr.length;i++){
// sum+=arr[i]
// }
// console.log(sum)
// }
// sumArr(arr)
//--
// //sumation of array
// let arr=[1,2,3,4,5,6]
// let b = arr.reduce((a,b)=> a+b ,0)
// console.log(b)
//====================
// //find the index for first appear for the string if doesn't there return -1
// let string = "sadbutsad", find = "sad";
// let index = -1;
// for (let i = 0; i <= string.length - find.length; i++) {
// for (let j = 0; j < find.length; j++) {
// if (string[i+j] !== find[j]) {
// console.log(string[i])
// }
// }
// }
// console.log(index)
// //========================
// //i want you calculate the a and b by code
// let arr1 = [1, 2, 3, 0, 0, 0], arr2 = [2, 5, 6,4];
// function arr(arr1, arr2) {
// let a = arr1.length - arr2.length;
// let b = arr2.length;
// for (let i = 0; i < b; i++) {
// arr1[a + i] = arr2[i];
// }
// arr1.sort((a, b) => a - b);
// return arr1;
// }
// console.log(arr(arr1, arr2));
//==================
///////////////////////////////////
// // pascal traingle array
// function pascal(numRows) {
// let arr=[]
// for(let i=0;i<numRows;i++){
// const row=[1]
// for(let j=1;j<i;j++){
// row[j] = arr[i - 1][j - 1] + arr[i - 1][j]
// }
// if(i>0) {row.push(1)}
// arr.push(row)
// }
// return arr
// };
// console.log(pascal())
//=====================
// // //index of pascal array
// var generate = function(n) {
// let row = [1];
// for (let i = 1; i <= n; i++) {
// let newRow = [1];
// for (let j = 1; j < row.length; j++) {
// newRow[j] = row[j - 1] + row[j];
// }
// newRow.push(1);
// row = newRow;
// }
// return row;
// };
// console.log(generate(3));
// //convert zero to end
// function arr1(arr) {
// let j = 0;
// for (let i = 0; i < arr.length; i++) {
// if (arr[i] !== 0) {
// if (i !== j) {
// arr[j] = arr[i];
// arr[i] = 0
// }
// j++;
// }
// }
// return arr;
// }
// console.log(arr1([0, 1, 0, 3, 4, 2]));
//================================
// //make it fancy
// function fancy(s) {
// let result = "";
// for (let i = 0; i < s.length; i++) {
// let last = result[result.length - 1];
// let secondLast = result[result.length - 2];
// if (s[i] === last && s[i] === secondLast) {
// continue;
// }
// result += s[i];
// }
// return result;
// };
// console.log(fancy('leeetcode'))
// //anotherr solution morrre optimal
// var makeFancyString = function(s) {
// let result = [];
// for (let i = 0; i < s.length; i++) {
// let len =result.length
// if (len >= 2 && s[i] === result[len-1] && s[i] === result[len-2]) {
// continue;
// }
// result.push(s[i])
// }
// return result.join('');
// };
// console.log(makeFancyString('leeetcode'))
//============================
// //index counterr
// function createCounter(n) {
// let a=n
// return function() {
// return a++;
// }
// }
// const counter = createCounter(-2);
// let calls = ["call", "call", "call", "call", "call"];
// let result =[]
// for (let i = 0; i < calls.length; i++) {
// result.push(counter());
// }
// console.log(result);
// //same char
// let strs =["fly","flower", "flow"]
// var longestCommonPrefix = function(strs) {
// if(strs.length === 0) return "";
// let result=""
// for(let i=0;i<strs[0].length;i++){
// let firstWord = strs[0][i]
// for(let j=1;j<strs.length ;j++){
// if(i >= strs[j].length || strs[j][i] !== firstWord){
// return result;
// }
// }
// result+=firstWord
// }
// return result
// };
// console.log(longestCommonPrefix(strs))
//================================================
// //check if its plindrom or not
// var isPalindrome = function(x) {
// if (x < 0) return false;
// let str = x.toString();
// let reversedStr = str.split('').reverse().join('');
// return str === reversedStr;
// };
// console.log(isPalindrome(121));