-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
2581 lines (1968 loc) · 60.7 KB
/
app.js
File metadata and controls
2581 lines (1968 loc) · 60.7 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
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//NUMBER
/*
*/
//MY SOLUTION
/*********THE ABOVE IS A TEMPLATE*************** */
//NUMBER 100
/*
https://www.codewars.com/kata/56d6b921c9ae3fd926000601/train/javascript
*/
//MY SOLUTION
const theString = (str) => {
}
//NUMBER 99
/*
https://www.codewars.com/kata/5546ea9bddfc5c0c38000026/train/javascript
*/
//MY SOLUTION
function Counter() {
let count = 0;
//quickly, now!
this.check = function() {
return count;
};
this.increment = function() {
count++
};
}
//NUMBER 98
/*
https://www.codewars.com/kata/632408defa1507004aa4f2b5/train/javascript
*/
//MY SOLUTION
/*
https://www.codewars.com/kata/5d774cfde98179002a7cb3c8/javascript
*/
//The Problem:
//This is a failed kata that I can come back to and look at later if I choose to.
//NUMBER 98
/*
https://www.codewars.com/kata/5882b052bdeafec15e0000e6/train/javascript
*/
//MY SOLUTION
class Quark{
constructor (color, flavor) {
let validColors = ["red","blue","green"];
let validFlavors = ['up', 'down', 'strange', 'charm', 'top', 'bottom']
this.color = color;
this.flavor = flavor;
this.baryon_number = 1/3;
if (!validColors.includes(color)) {
return "colors must be red, green or blue";
}
if (!validFlavors.includes(flavor)) {
return "flavor bust be up, down, strange, charm, top, or bottom ";
}
}
interact(otherQuark) {
const tempColor = this.color;
this.color = otherQuark.color;
otherQuark.color = tempColor;
}
}
//NUMBER 97
/*
https://www.codewars.com/kata/53d628de83db278fb1000710
*/
//MY SOLUTION
String.prototype.myNewMethod = function() {
return this.toUpperCase();
};
//NUMBER 96
/*
https://www.codewars.com/kata/56fcc1ee45040039ab0016da
*/
//MY SOLUTION
class Cube {
constructor(length) {
this.length = length;
}
// --- Surface Area ---
get surfaceArea() {
return 6 * this.length ** 2;
}
set surfaceArea(area) {
this.length = Math.sqrt(area / 6);
}
// --- Volume ---
get volume() {
return this.length ** 3;
}
set volume(vol) {
this.length = Math.cbrt(vol);
}
}
//NUMBER 95
/*
https://www.codewars.com/kata/6089c7992df556001253ba7d
*/
//MY SOLUTION
function Song(title, artist) {
this.title = title;
this.artist = artist;
this.listeners = [];
this.howMany = function(array) {
let newListeners = 0;
for (let i = 0; i < array.length; i++) {
const listener = array[i].toLowerCase();
if (!this.listeners.includes(listener)) {
this.listeners.push(listener);
newListeners++;
}
}
return newListeners;
};
}
//NUMBER 94
/*
https://www.codewars.com/kata/56fbdda707cff41b68000de2/train/javascript
*/
//MY SOLUTION
//NUMBER 93
/*
https://www.codewars.com/kata/534fcca5edb124cfe6000f60/javascript
*/
//MY SOLUTION
//NUMBER 92
/*
https://www.codewars.com/kata/513e1e47c600c93cef000001
*/
//MY SOLUTION
class Animal {
constructor(name = "name", type="type") {
this.name = name;
this.type = type;
}
toString () {
return `${this.name} is a ${this.type}`
}
}
//NUMBER 91
/*
https://www.codewars.com/kata/5121303128ef4b495f000001
*/
//MY SOLUTION
class Person {
constructor(name) {
this.name = name;
}
greet(yourName) {
return `Hello ${yourName}, my name is ${this.name}`;
}
}
//NUMBER 90
/*
https://www.codewars.com/kata/55b75fcf67e558d3750000a3
*/
//MY SOLUTION
class Block{
constructor([width, length, height]){
this.width = width
this.length = length
this.height = height
}
getWidth() {
return this.width
}
getLength() {
return this.length
}
getHeight() {
return this.height
}
getVolume() {
return this.width * this.length * this.height;
}
getSurfaceArea() {
return 2 * (this.width * this.length +
this.width * this.height +
this.length * this.height);
}
}
//NUMBER 89
/*
https://www.codewars.com/kata/56951add53eccacf44000030
*/
//MY SOLUTION
function Dog(name, age, breed, vaccinated, wormed) {
this.name = name;
this.age = age;
this.breed = breed;
this.vaccinated = vaccinated;
this.wormed = wormed;
}
Dog.prototype.checkDog = function() {
if (this.vaccinated && this.wormed) {
return `${this.name} can be accepted`;
} else if (this.vaccinated || this.wormed) {
return `${this.name} can only be accepted by itself`;
} else {
return `${this.name} can not be accepted`;
}
};
//NUMBER 88
/*
https://www.codewars.com/kata/56f935002e6c0d55fa000d92
*/
//MY SOLUTION
class Shark extends Animal {
constructor(name, age, status) {
super(name, age, 0, "shark", status);
}
}
class Cat extends Animal {
constructor(name, age, status) {
super(name, age, 4, "cat", status)
}
introduce() {
return `${super.introduce()} Meow meow!`;
}
}
class Dog extends Animal {
constructor(name, age, status, master) {
super(name, age, 4, "dog", status)
this.master = master
}
greetMaster() {
return `Hello ${this.master}`
}
}
//NUMBER 87
/*
https://www.codewars.com/kata/56f935002e6c0d55fa000d92/train/javascript
*/
//MY SOLUTION
class Shark extends Animal {
constructor(name, age, status) {
super(name, age, 0, "shark", status);
}
}
class Cat extends Animal {
constructor(name, age, status) {
super(name, age, 4, "cat", status)
}
introduce() {
return `${super.introduce()} Meow meow!`;
}
}
class Dog extends Animal {
// On your own now - you can do it :D
}
//NUMBER 86
/*
https://www.codewars.com/kata/52b50a20fa0e77b304000103
*/
//MY SOLUTION
function isSantaClausable(obj) {
const hasSayHoHoHo = typeof obj.sayHoHoHo === 'function';
const hasDistributeGifts = typeof obj.distributeGifts === 'function';
const hasGoDownTheChimney = typeof obj.goDownTheChimney === 'function';
return hasSayHoHoHo && hasDistributeGifts && hasGoDownTheChimney;
}
//NUMBER 85
/*
https://www.codewars.com/kata/5800e9b515e97e7cbb00154f
*/
//MY SOLUTION
function areaVolume(a,b,h,l) {
let volume = Math.round(0.5 * (a + b) * h * l);
let base_area = (a + b) * h;
let leg_length = Math.sqrt(((b - a) / 2) ** 2 + h ** 2);
let perimeter = a + b + 2 * leg_length;
let lateral_area = perimeter * l;
let total_surface_area = Math.round(base_area + lateral_area);
return [total_surface_area, volume];
}
//NUMBER 84
/*
https://www.codewars.com/kata/5a5c118380eba8a53d0000ce/javascript
*/
//MY SOLUTION
function convertMyDollars(usd, currency) {
let statement;
let rate = CONVERSION_RATES[currency];
let binate = parseInt(rate.toString(), 2);
switch (currency) {
case "Argentinian Peso":
statement = `You now have ${usd * 10} of ${currency}.`;
break;
case "Armenian Dram":
statement = `You now have ${usd * 478} of ${currency}.`;
break;
case "Egyptian Pound":
statement = `You now have ${usd * 18} of ${currency}.`;
break;
case "Indian Rupee":
statement = `You now have ${usd * 63} of ${currency}.`;
break;
case "Uzbekistani Som":
statement = `You now have ${usd * 10000} of ${currency}.`;
break;
default:
statement = `You now have ${usd * binate} of ${currency}.`;
}
return statement
}
//NUMBER 83
/*
https://www.codewars.com/kata/57c6b44f58da9ea6c20003da
*/
//MY SOLUTION
function geo_mean(nums, arith_mean) {
let n = nums.length + 1;
let sumKnown = nums.reduce((acc, num) => acc + num, 0);
let missingNumber = (arith_mean * n) - sumKnown;
let fullList = [...nums, missingNumber];
let product = fullList.reduce((acc, num) => acc * num, 1);
return Math.pow(product, 1 / n);
}
//NUMBER 82
/*
https://www.codewars.com/kata/52c32ef251f31ae8f50000ae/solutions
*/
//MY SOLUTION
function updateAverage(currentAverage, numRatings, newRating) {
return (currentAverage * numRatings + newRating) / (numRatings + 1);
}
//NUMBER 81
/*
https://www.codewars.com/kata/558445a88826e1376b000011
*/
//MY SOLUTION
function age(x, y){
return (x * y) /(y-1)
}
//NUMBER 80
/*
https://www.codewars.com/kata/53222010db0eea35ad000001
*/
//MY SOLUTION
function getSlope(p1, p2) {
let slopeY = p2[1] - p1[1];
let slopeX = p2[0] - p1[0];
if (slopeX === 0 || p2 === p1) {
return null;
}
else {
return slopeY / slopeX;
}
}
//NUMBER 79
/*
https://www.codewars.com/kata/58aed2cafab8faca1d000e20
*/
//MY SOLUTION
function modifiedSum(a, n) {
// Write your code here
let theSum = 0;
let theOtherSum = 0;
for (let i = 0; i < a.length; i++) {
theOtherSum += a[i];
theSum+=a[i]**n;
}
return theSum - theOtherSum;
}
//NUMBER 78
/*
https://www.codewars.com/kata/63f96036b15a210058300ca9
*/
//MY SOLUTION
function secondSymbol(s, symbol) {
let letterCollection = [];
for (let i=0; i < s.length; i++) {
if (s[i] == symbol) {
letterCollection.push(i)
}
}
if (letterCollection.length < 2) {
return -1
}
else {
return letterCollection[1]
}
}
//NUMBER 77
/*
https://www.codewars.com/kata/6402205dca1e64004b22b8de/train/javascript
*/
//MY SOLUTION
function findCaterer(budget, people) {
if (people <= 0 || budget < 15 * people) return -1;
const price3 = people > 60 ? 24 * people : 30 * people;
const price2 = 20 * people;
const price1 = 15 * people;
if (price3 <= budget) return 3;
if (price2 <= budget) return 2;
if (price1 <= budget) return 1;
return -1;
}
//NUMBER 76
/*
https://www.codewars.com/kata/6409aa6df4a0b773ce29cc3d/train/javascript
*/
//MY SOLUTION
function realNumbers(n){
let collectionArray = [];
let sum = 0;
while (sum < n) {
sum = sum + 1;
if (sum % 2 !== 0 && sum % 3 !== 0 && sum % 5 !== 0) {
collectionArray.push(sum)
}
}
return collectionArray.length
}
//NUMBER 75
/*
https://www.codewars.com/kata/643ea1adef815316e5389d17
*/
//MY SOLUTION
function quadrantSegment(A, B) {
const oppositeX = (A.x > 0 && B.x < 0) || (A.x < 0 && B.x > 0)
const oppositeY = (A.y > 0 && B.y < 0) || (A.y < 0 && B.y > 0)
return oppositeX || oppositeY
}
//NUMBER 74
/*
https://www.codewars.com/kata/664e4f5b12b1b20182ea3e3a/train/javascript
*/
//MY SOLUTION
function whichPostcode(postcode){
let firstSeg = postcode.slice(postcode[0], postcode.indexOf(' '));
let secondSeg = postcode.slice(postcode.indexOf(' ') + 1);
if (
(/^[a-zA-Z]$/.test(firstSeg[0]) === true && /^[a-zA-Z]$/.test(firstSeg[1]) === true) ||
(/^[a-zA-Z]$/.test(firstSeg[0]) === true && /^\d$/.test(firstSeg[1]) === true) &&
/^\d$/.test(firstSeg[2] === true)
)
{
return "GB"
}
else if (
/^\d$/.test(postcode[0])=== true &&
/^\d$/.test(postcode[1]) === true &&
/^\d$/.test(postcode[2]) === true &&
postcode[3] === ' ' &&
/^\d$/.test(postcode[4]) === true &&
/^\d$/.test(postcode[5]) === true
)
{
return "SK"
}
}
//NUMBER 73
/*
https://www.codewars.com/kata/64fc03a318692c1333ebc04c
*/
//MY SOLUTION
function bestFriend(txt, a, b) {
for (let i = 0; i < txt.length; i++) {
if (txt[i] === a) {
if (i === txt.length-1) {
return false
}
if (txt[i+1] !== b) {
return false
}
}
}
return true
}
//NUMBER 72
/*
https://www.codewars.com/kata/65a024af6063fb0ac8c0f0b5/train/javascript
*/
//MY SOLUTION
function hasScored(s) {
if (s==="") {
return false;
}
else {
}
}
//NUMBER 71
/*
https://www.codewars.com/kata/65c0161a2380ae78052e5731
*/
//MY SOLUTION
function stonePick(arr) {
let cobblestoneCount = 0;
let stickCount = 0;
let woodCount = 0;
for (const item of arr) {
if (item === "Cobblestone") {
cobblestoneCount++;
} else if (item === "Sticks") {
stickCount++;
} else if (item === "Wood") {
woodCount++;
}
}
stickCount += woodCount * 4;
const pickaxesFromCobbleStone = Math.floor(cobblestoneCount / 3);
const pickaxesFromSticks = Math.floor(stickCount / 2);
const maxPickaxes = Math.min(pickaxesFromCobbleStone, pickaxesFromSticks);
return maxPickaxes;
}
//NUMBER 70
/*
You're given a two-dimensional array of integers matrix. Your task is to determine
the smallest non-negative integer that is not present in this array.
Input/Output
[input] 2D integer array matrix
A non-empty rectangular matrix.
1 ≤ matrix.length ≤ 10
1 ≤ matrix[0].length ≤ 10
[output] an integer
The smallest non-negative integer that is not present in matrix.
Example
For
matrix = [ [0, 2], [5, 1]] the result should be 3
0,1,2,(3)...5
*/
//MY SOLUTION
function smallestInteger(matrix) {
const flattened = matrix.flat();
flattened.sort((a, b) => a - b);
let smallestMissing = 0;
for (let num of flattened) {
if (num === smallestMissing) {
smallestMissing++;
} else if (num > smallestMissing) {
break;
}
}
return smallestMissing;
}
//NUMBER 69
/*
Step through my green glass door.
You can take the moon, but not the sun.
You can take your slippers, but not your sandals.
You can go through yelling, but not shouting.
You can't run through fast, but you can run with speed.
You can take a sheet, but not your blanket.
You can wear your glasses, but not your contacts.
Have you figured it out? Good! Then write a program that can figure it out as well.
*/
//MY SOLUTION
function stepThroughWith(s) {
s = s.toLowerCase();
for (let i = 0; i < s.length - 1; i++) {
if (s[i] === s[i + 1]) {
return true;
}
}
return false;
}
//NUMBER 68 failed kata
/*
ou have clothes international size as text (xs, s, xxl).
Your goal is to return European number size as a number from that size.
Notice that there is arbitrary amount of modifiers (x), excluding m size, and input can be any string.
Linearity
Base size for medium (m) is 38.
(then, small (s) is 36, and large (l) is 40)
The scale is linear; modifier x continues that by adding or subtracting 2 from resulting size.
(For sizes where x modifier makes total size negative, treat that as OK, and return negative size)
Invalid cases
Function should handle wrong/invalid sizes.
Valid input has any base size (s/m/l) and any amount of modifiers (x) before base size (like xxl).
Notice that you cannot apply modifier for m size, consider that case as invalid!
Anything else is disallowed and should be considered as invalid (None for Python, 0, false for Go, null for JavaScript).
Invalid examples: xxx, sss, xm, other string
*/
//MY SOLUTION by deepseek AI
function sizeToNumber(size) {
// Handle invalid input (empty string, null, undefined, etc.)
if (!size || typeof size !== 'string') {
return null;
}
// Convert to lowercase for case insensitivity
size = size.toLowerCase();
// Find the base size (s, m, l) and count the number of 'x' modifiers
let baseSize = '';
let xCount = 0;
for (let i = 0; i < size.length; i++) {
const char = size[i];
if (char === 's' || char === 'm' || char === 'l') {
// If base size is already found, it's invalid (e.g., 'ss', 'sm')
if (baseSize !== '') {
return null;
}
baseSize = char;
} else if (char === 'x') {
xCount++;
} else {
// If any invalid character is found, return null
return null;
}
}
// If no base size is found, it's invalid
if (baseSize === '') {
return null;
}
// Check if modifiers are applied to 'm' (invalid case)
if (baseSize === 'm' && xCount > 0) {
return null;
}
// Calculate the base European size
let europeanSize;
switch (baseSize) {
case 's':
europeanSize = 36;
break;
case 'm':
europeanSize = 38;
break;
case 'l':
europeanSize = 40;
break;
default:
return null; // Invalid base size (should not happen)
}
// Apply modifiers
// For 's' and 'l', each 'x' subtracts or adds 2, respectively
if (baseSize === 's') {
europeanSize -= xCount * 2; // Subtract for smaller sizes
} else if (baseSize === 'l') {
europeanSize += xCount * 2; // Add for larger sizes
}
// Return the final European size
return europeanSize;
}
//NUMBER 67 -- failed kata
/*
given an array of integers, which represent the stones, and your task is
to assemble the highest-value pyramid from them. The pyramid is made out of exactly three layers, containing:
Top layer: 1 integer
Middle layer: 2 identical integers
Bottom layer: 3 identical integers
Additionally, no integer can appear in two or more layers. That is,
each layer is made from stones of the same value, and stones of the same value can be used at most in one layer.
Graphically, the structure of the pyramid looks like this, where
x
≠
y
≠
z
x
=y
=z
[z]
[y] [y]
[x][x][x]
Input
The input is an array that may contain positive and negative integers,
as well as zeros. The integers are in no specific order and can be repeated. The array may also be empty.
Output
The output is a single integer – the sum of all integers that make up the pyramid.
For example, given input [1,1,1,2,2,2,3,3,3], the highest-value pyramid is:
[1]
[2] [2]
[3][3][3]
And the sum is thus:
3
⋅
3
+
2
⋅
2
+
1
=
14
3⋅3+2⋅2+1=14.
If it's not possible to build a
pyramid from the given array (e.g. [-1,-1,0,0,1,1] or an empty one []), return None, null,
or other language-specific alternative.
*/
//MY SOLUTION
function pyramid(stones) {
let prepStones = stones.sort((a, b) => a - b)
let layerOne = prepStones[0]
let layerTwo = []
let layerThree = []
let sumTwo
let sumThree
for (let i = 0; i < prepStones.length; i++) {
if ((layerOne !== prepStones[i]) && layerTwo.length !== 2) {
layerTwo.push(prepStones[i])
sumTwo = layerTwo[0] + layerTwo[1]
}
if ((layerOne !== prepStones[i]) && layerTwo.includes(prepStones[i]) == false && layerThree.length !== 3) {
layerThree.push(prepStones[i])
sumThree = layerThree[0] + layerThree[1] + layerThree[2]
}
}
let finals = layerOne + sumTwo + sumThree
}
//NUMBER 66 failed kata
/*
Multiply the adjacent digits which are not separated by a '-' or a '+' in a string, then do the sum.
For example:
"53+5" -> 20, which is 5 * 3 + 5
"266-66" -> 36, which is 2 * 6 * 6 - 6 * 6
"555" -> 125, which is 5 * 5 * 5
*/
//MY SOLUTION
function digitMultiplication(expr) {
let multiBoxLeft = []
let multiBoxRight = []
if (expr.includes('+')) {
multiBoxLeft.push(expr[0], expr[expr.indexOf('+') - 1])
multiBoxRight.push(expr[expr.indexOf('+') + 1], expr[expr.length - 1])
}
return multiBoxRight
}
//NUMBER 65
/*
Your task is to create a function that takes two parameters:
text: A string containing the text to be wrapped in comments.
style: A string indicating the style of comments to use. It can be one of the following:
"Bash"
"Bash Multiline"
"JavaDoc"
"Python"
"Python Multiline"
"Javascript"
"Javascript Multiline"
"SGML"
"SQL"
The function should wrap the given text in the appropriate comment style and return the result.
*/
//MY SOLUTION
function comment(text, style) {
const lines=text.split('\n')
switch(style) {
case "Bash":
case "Python":
return lines.map(line=>`# ${line}`).join('\n')
break;
case "Bash Multiline":
return `: "\n${text}\n"`
break;
case "JavaDoc":
return `/**\n${lines.map(line=> `* ${line}`).join('\n')}\n*/`
break;
case "Python Multiline":
return `"""\n${text}\n"""`
break;
case "Javascript":
return lines.map(line=>`// ${line}`).join('\n')
break;
case "Javascript Multiline":
return `/*\n${text}\n*/`
break;