-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
5701 lines (4183 loc) · 139 KB
/
script.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
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
/*
Your classmates asked you to copy some paperwork for them. You know that there are 'n' classmates and the paperwork has 'm' pages.
Your task is to calculate how many blank pages do you need. If n < 0 or m < 0 return 0.
Example:
n= 5, m=5: 25
n=-5, m=5: 0
*/
const paperwork = (n, m) => {
// n = classmates , m = paperwork to copy
if (n < 0 || m < 0) {
return 0;
} else {
return n * m;
}
};
let copypages = paperwork(0, 10);
console.log(copypages);
/*
Can you find the needle in the haystack?
Write a function findNeedle() that takes an array full of junk but containing one "needle"
After your function finds the needle it should return a message (as a string) that says:
"found the needle at position " plus the index it found the needle, so:
Example(Input --> Output)
["hay", "junk", "hay", "hay", "moreJunk", "needle", "randomJunk"] --> "found the needle at position 5"
//``
*/
const findeNeedle = (arr) => {
return arr;
};
isNeedle = findeNeedle([
"hay",
"junk",
"hay",
"hay",
"moreJunk",
"needle",
"randomJunk",
"plastic",
]);
arr2 = [
"hay",
"junk",
"hay",
"hay",
"moreJunk",
"needle",
"randomJunk",
"plastic",
];
/*
function findNeedle(arr) {
if (arr.includes("needle")) {
return `found the needle at position ${arr.indexOf("needle")}`;
} else {
return `there isnt needle in the junk`;
}
}
*/
/*
const findNeedle = (arr) => {
let num = arr.indexOf("needle");
if (num != 0) {
return `found the needle at position ${num}`;
} else {
return `There isnt needle`;
}
};
*/
//let result = findNeed(arr2);
//console.log(result);
/*
if (e == "needle") {
return `found the needle at position ${index}`;
} else {
return "There is not needle in the array";
}
*/
//
/*
let dna = "GCATCATTAAAAT";
//let result = dna.replaceAll("T", "U");
//console.log(result);
function DNAtoRNA(dna) {
if (dna != "") {
let separation = dna.split("");
for (let i = 0; i < separation.length; i++) {
if (separation[i] == "T") {
separation[i] = "U";
}
}
return separation.join("");
} else {
return "There isnt input";
}
}
let result2 = DNAtoRNA(dna);
console.log(result2);
/*
const DNAtoRNA = (dna) => {
if (dna != "") {
return dna.replaceAll("T", "U");
} else {
return "there is not input";
}
};
let final = DNAtoRNA("");
console.log(final);
*/
/*
const arr = [];
function sumArray(array) {
let arr = [...array];
if (arr == null) {
return 0;
}
const max = Math.max(...arr);
const min = Math.min(...arr);
let tempArr = [];
arr.filter((number) => {
if (number != max && number != min) {
tempArr.push(number);
} else {
tempArr.push(0);
}
});
let total = tempArr.reduce((acc, sum) => acc + sum, 0);
return total;
}
*/
///console.log(sumArray([-6, -20, -1, -10, -12]), -28);
/*
let test = [[1, 2], [3, 4, 5], 6, null, undefined];
let emptyArr = [];
let c = test.map((e) => {
if (Array.isArray(e)) {
console.log(e);
let emptyArr1 = [...e];
emptyArr1.forEach((e) => emptyArr.push(e));
} else {
emptyArr.push(e);
}
});
console.log(c);
console.log(emptyArr);
console.log(test);
/////
/*
function sumArray(arr) {
if (arr == null || arr == undefined) {
return 0;
} else {
let emptyArr = [];
arr.forEach((e) => {
if (Array.isArray(e)) {
let isArray = [...e];
isArray.forEach((i) => emptyArr.push(i));
} else if (e == null) {
emptyArr.push(0);
} else {
emptyArr.push(e);
}
});
const max = Math.max(...emptyArr);
const min = Math.min(...emptyArr);
console.log(max);
console.log(min);
// Now excluding the max and min values
let tempArr = [];
emptyArr.filter((number) => {
if (number != max && number != min) {
tempArr.push(number);
} else {
tempArr.push(0);
}
});
let total = tempArr.reduce((acc, sum) => acc + sum, 0);
return total;
}
}
console.log(sumArray([10, 1, 6, 10, 10]));
*/
//
/*
let test3 = [10, 1, 6, 10, 10];
function sumArray(arr) {
if (arr == null) {
return 0;
} else {
let sortedArray = arr.sort((a, b) => a - b);
if (arr == null || sortedArray.length == 1 || sortedArray.length == 2) {
return 0;
} else {
let myArr = [];
for (let i = 1; i < arr.length - 1; i++) {
myArr.push(arr[i]);
}
let total = myArr.reduce((acc, sum) => acc + sum, 0);
return total;
}
}
}
*/
//console.log(sumArray1([null]));
//let spreadArray = [...sortedArray]
//Write a function which calculates the average of the numbers in a given list.
//Note: Empty arrays should return 0.
/*
function find_average(array) {
if (array == null || array.length == 0) {
return 0;
} else {
let avg = array.reduce((acc, sum) => acc + sum, 0) / array.length;
return avg;
}
}
console.log(find_average([]));
*/ /*
function find_average(array) {
let avg = 0;
array == null || array.length == 0
? 0
: (avg = array.reduce((acc, sum) => acc + sum, 0) / array.length);
return avg;
}
*/
//console.log(find_average([]));
//Write a function that takes an array of numbers and returns the sum of the numbers. The numbers can be negative or non-integer. If the array does not contain any numbers then you should return 0.
//let arr12 = [-3, -2, -1, 1];
/*
function sum(numbers) {
if (numbers != null) {
let result = numbers.reduce((acc, sum) => acc + sum, 0);
return result;
} else {
return 0;
}
}
*/
//Given a random non-negative number, you have to return the digits of this number within an array in reverse order.
//348597 => [7,9,5,8,4,3]
//Note: split only works with strings, if you are handling numbers, you have to convert them first to string.
//Here you apply toString() , Number , map, reverse
/*
const num = 12345;
function digitize(n) {
let result = n.toString().split("").reverse();
result = result.map((e) => Number(e));
return result;
}
/*
const result = digitize(0);
const digitize = (n) => n.toString().split("").reverse();
*/
/*
console.log(digitize(num));
const reverseNumber = (number) => {
return number
.toString()
.split("")
.reverse()
.map((e) => Number(e));
};
console.log(reverseNumber(6789));
*/
//Very simple, given an integer or a floating-point number, find its opposite.
//1: -1 / 14: -14 / -34: 34
//const opposite = (number) => -number;
//console.log(opposite(-1));
/*
Write a function that accepts an integer n and a string s as parameters, and returns a string of s repeated exactly n times.
6, "I" -> "IIIIII"
5, "Hello" -> "HelloHelloHelloHelloHello"
function repeatStr(n, s) {
let str = "";
for (let i = 0; i < n; i++) {
str = str + s;
}
return str;
}
const repeatS = (n, s) => s.repeat(n);
console.log(repeatS(2, "hi"));
*/
/*
Given a non-negative integer, 3 for example, return a string with a murmur: "1 sheep...2 sheep...3 sheep...". Input will always be valid, i.e. no negative integers.
*/
/*
function murmur(n) {
let str = [];
for (let i = 1; i <= n; i++) {
let mur = i + " sheep...";
str.push(mur);
}
let mur = str.toString();
return mur;
}
console.log(murmur(4));
*/
/*
function murmur(n) {
let temp = "";
let str = "";
for (let i = 1; i <= n; i++) {
str = i + " sheep...";
temp = temp + str;
}
return temp;
}
console.log(murmur(2));
*/
/*
// Create a function that returns "hello world1!" be creative
function greet() {
const binary = [
1101000, 1100101, 1101100, 1101100, 1101111, 100000, 1110111, 1101111,
1110010, 1101100, 1100100, 100001,
];
str = "";
binary.forEach((e) => {
str += String.fromCharCode(parseInt(e, 2));
});
return str;
}
console.log(greet());
*/
input = [
[18, 20],
[45, 2],
[61, 12],
[37, 6],
[21, 21],
[78, 9],
];
output = ["Open", "Open", "Senior", "Open", "Open", "Senior"];
/*
function openOrSenior(data) {
let result = [];
for (let i = 0; i < data.length; i++) {
const age = data[i][0];
const handicap = data[i][1];
if (age >= 55 && handicap > 7) {
result.push("senior");
} else {
result.push("open");
}
}
return result;
}
let r = openOrSenior(input);
console.log(r);
let result = [];
let position = [];
for (let i = 0; i < input.length; i++) {
for (let j = 0; j < 2; j++) {
console.log(input[i][j]);
let firstPosition = input[i][j];
let secondPosition = input[i][j + 1];
if (firstPosition >= 55 && secondPosition > 7) {
result.push("Senior");
} else {
result.push("Open");
}
}
}
console.log(result);
*/
///
/*
Parameters:
*/
///
/*
//Create a function that returns the sum of the two lowest positive numbers given an array of minimum 4 positive integers. No floats or non-positive integers will be passed.
//For example, when an array is passed like [19, 5, 42, 2, 77], the output should be 7.
const input1 = [28, 87, 7, 15, 45];
function sumTwoSmallestNumbers(numbers) {
let sortedList = [];
sortedList = numbers.sort((a, b) => a - b);
let result = sortedList[0] + sortedList[1];
return result;
}
console.log(sumTwoSmallestNumbers(input1));
*/
//ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits or exactly 6 digits.
//If the function is passed a valid PIN string, return true, else return false.
//"1234" --> true
//"12345" --> false
//"a234" --> false
/*
function validatePin(pin) {
if (Number(pin)) {
if (pin.length == 4 || pin.length == 6) {
return true;
} else {
return false;
}
} else {
return false;
}
}
*/
// Validate pin
/*
const pin = "123\n";
function validatePin(pin) {
const text = pin;
const match = /\r|\n/.exec(text);
if (pin.includes(match)) {
return false;
}
let result = [];
const n = pin.split("");
console.log(n.length);
if (n.includes(".") || n.includes("-")) {
return false;
} else {
n.forEach((e) => {
if (e == " " || e == "\n") {
return false;
} else {
if (Number(e) >= 0) {
result.push(e);
} else {
return false;
}
}
});
}
// Now checking that result has lenght ==4 or ==6
if (n.length === result.length) {
if (result.length == 4 || result.length == 6) {
return true;
} else {
return false;
}
} else {
return false;
}
}
console.log(validatePin(pin));
/*
if (Number(pin) && Number(pin) % 1 === 0) {
let split = pin.split("");
split.forEach((e) => {
if (e >= 0) {
result.push(e);
}
});
if (result.length == 4 || result.length == 6) {
return true;
} else {
return false;
}
} else {
return false;
}
*/
/*
const text = pin; //"abc\n123";
const match = /\r|\n/.exec(text);
console.log(match);
if (pin.includes(match)) {
console.log("hmmm");
}
*/
/*
An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case.
Example: (Input --> Output)
"Dermatoglyphics" --> true
"aba" --> false
"moOse" --> false (ignore letter case)
STRINGSFUNDAMENTALS
function split(str) {
if (str == "") {
return true;
} else {
const s = str.toLowerCase();
const separate = s.split("");
let tempArr = [];
let checker = true;
if (checker == true) {
for (let i = 0; i < separate.length; i++) {
let tempArr = separate.filter((e) => e == separate[i]);
console.log(tempArr);
if (tempArr.length > 1) {
checker = false;
break;
}
}
}
return checker;
}
}
// Solution by other user in codewars
function isIsogram(str){
let value = true;
str.toLowerCase().split('').sort().map((letter, index, array) => {
if (letter === array[index + 1]) value = false;
});
return value;
}
const test3 = isIsogram("aba");
console.log(test3);
*/
/*
*/
/*
In a factory a printer prints labels for boxes. For one kind of boxes the printer has to use colors which, for the sake of simplicity, are named with letters from a to m.
The colors used by the printer are recorded in a control string. For example a "good" control string would be aaabbbbhaijjjm meaning that the printer used three times color a, four times color b, one time color h then one time color a...
Sometimes there are problems: lack of colors, technical malfunction and a "bad" control string is produced e.g. aaaxbbbbyyhwawiwjjjwwm with letters not from a to m.
You have to write a function printer_error which given a string will return the error rate of the printer as a string representing a rational whose numerator is the number of errors and the denominator the length of the control string. Don't reduce this fraction to a simpler expression.
The string has a length greater or equal to one and contains only letters from ato z.
Examples:
s="aaabbbbhaijjjm"
printer_error(s) => "0/14"
s="aaaxbbbbyyhwawiwjjjwwm"
printer_error(s) => "8/22"
*/
/*
function printerError(s) {
let acc = 0;
let sLenght = s.length;
const sampleErrors = [
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
];
let sample = s.split("");
sample.forEach((e) => {
//let numberErrors = sampleErrors.filter((element) => element.includes(e));
sampleErrors.forEach((element) => {
if (element == e) {
acc = acc + 1;
}
});
});
let result = acc + "/" + sLenght;
return result;
}
// Refactoring the previous solution
/*
const label = "aaaxbbbbyyhwawiwjjjwwm";
function filterStr(str) {
let sampleError = str.split("").filter((e) => e > "m");
const numError = sampleError.length + "/" + str.length;
return numError;
}
filterStr(label);
*/
/*
Implement a function that accepts 3 integer values a, b, c. The function should return true if a triangle can be built with the sides of given length and false in any other case.
function isTriangle(a, b, c) {
const prop1 = a + b > c;
const prop2 = b + c > a;
const prop3 = c + a > b;
if (prop1 && prop2 && prop3) {
return true;
} else {
return false;
}
}
console.log(isTriangle(2, 2, 2));
*/
/*Your task is to convert strings to how they would be written by Jaden Smith. The strings are actual quotes from Jaden Smith, but they are not capitalized in the same way he originally typed them.
Example:
Not Jaden-Cased: "How can mirrors be real if our eyes aren't real"
Jaden-Cased: "How Can Mirrors Be Real If Our Eyes Aren't Real" */
/*
// This function is correct, but isnt in the format requested by the kata
function toJadenCase(str) {
const split = str.split(" ");
let phrase = "";
for (let i = 0; i < split.length; i++) {
let firstLetter = split[i].substring(0, 1).toUpperCase();
let restLetters = split[i].substring(1, split[i].length);
phrase = phrase + firstLetter + restLetters + " ";
}
return phrase;
}
// Correct Answer using prototype
String.prototype.toJadenCase = function () {
return this.split(" ")
.map((item) => item[0].toUpperCase() + item.slice(1))
.join(" ");
};
console.log(str.toJadenCase());
//
String.prototype.toJadenCase = function() {
return this
.split(" ")
.map(i => i.replace(i[0], i[0].toUpperCase()))
.join(" ");
};
*/
/*
Implement a function that adds two numbers together and returns their sum in binary. The conversion can be done before, or after the addition.
The binary number returned should be a string.
Examples:(Input1, Input2 --> Output (explanation)))
1, 1 --> "10" (1 + 1 = 2 in decimal or 10 in binary)
5, 9 --> "1110" (5 + 9 = 14 in decimal or 1110 in binary)
function addBinary(a, b) {
let result = a + b;
return result.toString(2);
}
console.log(addBinary(10, 40));
// this time, they give us an array with 0s and 1s to convert from binary to decimal
const result = 10;
let x = "101010";
console.log(parseInt(x, 2));
let arr = [0, 0, 0, 1];
arr = arr.join("");
const binaryArrayToNumber = (arr) => {
const result = arr.join("");
return parseInt(result, 2);
};
console.log(binaryArrayToNumber([0, 0, 0, 1]));
*/
/*
Given a set of numbers, return the additive inverse of each. Each positive becomes negatives, and the negatives become positives.
invert([1,2,3,4,5]) == [-1,-2,-3,-4,-5]
invert([1,-2,3,-4,5]) == [-1,2,-3,4,-5]
invert([]) == []
You can assume that all values are integers. Do not mutate the input array/list.
function invert(array) {
if (array) {
let inverted = array.map((e) => e * -1);
return inverted;
} else {
return;
}
}
console.log(invert([-1, 2, -3, 4, -5]));
*/
/*
Build a function that returns an array of integers from n to 1 where n>0.
Example : n=5 --> [5,4,3,2,1]
const reverseSeq = (n) => {
let arr = [];
while (n > 0) {
if (n != 0) {
arr.push(n);
}
n--;
}
return arr;
};
const reverseSeq = (n) => {
return Array(n)
.fill(0)
.map((e, i) => n - i);
};
console.log(reverseSeq(4));
*/
/*
Return the number (count) of vowels in the given string.
We will consider a, e, i, o, u as vowels for this Kata (but not y).
The input string will only consist of lower case letters and/or spaces.
let str = "pear tree";
function vowels(str) {
let arr = str
.split("")
.filter((e) => e == "a" || e == "e" || e == "i" || e == "o" || e == "u");
return arr;
}
console.log(vowels(str));
*/
/*
In this little assignment you are given a string of space separated numbers, and have to return the highest and lowest number.
Examples
highAndLow("1 2 3 4 5"); // return "5 1"
highAndLow("1 2 -3 4 5"); // return "5 -3"
highAndLow("1 9 3 4 -5"); // return "9 -5"
//Solution
let str = "1 2 3 4 5";
function highAndLow(numbers) {
let arr = numbers.split(" ").sort((a, b) => a - b);
return arr[arr.length - 1] + " " + arr[0];
}
console.log(highAndLow(str));
*/
/*
Check to see if a string has the same amount of 'x's and 'o's. The method must return a boolean and be case insensitive. The string can contain any char.
Examples input/output:
XO("ooxx") => true
XO("xooxx") => false
XO("ooxXm") => true
XO("zpzpzpp") => true // when no 'x' and 'o' is present should return true
XO("zzoo") => false
// Solution
function XO(str) {
let arr = str.toLowerCase().split("");
let countX = arr.filter((e) => e == "x");
let countO = arr.filter((e) => e == "o");
const lenghtX = countX.length;
const lengthO = countO.length;
if (lenghtX === lengthO) {
return true;
} else {
return false;
}
}
const str = "zzoo";
console.log(XO(str));
*/
/*
Complete the method that takes a boolean value and return a "Yes" string for true, or a "No" string for false.
// Solution
function boolToWord(bool) {
return bool === true ? "Yes" : "No";
}
console.log(boolToWord(false));
*/
/*
Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love.
Write a function that will take the number of petals of each flower and return true if they are in love and false if they aren't.
My solution:
function lovefunc(flower1, flower2) {
const result = flower1 % 2 == 0 ? true : false;
const result2 = flower2 % 2 == 0 ? true : false;
return (result && result2) || (!result && !result2) ? false : true;
}
Clever solution:
function lovefunc(flower1, flower2){
return flower1 % 2 !== flower2 % 2;
}
*/
/*
There is a bus moving in the city, and it takes and drop some people in each bus stop.
You are provided with a list (or array) of integer pairs. Elements of each pair represent number of people get into bus (The first item) and number of people get off the bus (The second item) in a bus stop.
Your task is to return number of people who are still in the bus after the last bus station (after the last array). Even though it is the last bus stop, the bus is not empty and some people are still in the bus, and they are probably sleeping there :D
Take a look on the test cases.
Please keep in mind that the test cases ensure that the number of people in the bus is always >= 0. So the return integer can't be negative.
The second value in the first integer array is 0, since the bus is empty in the first bus stop
var number = function (busStops) {
return busStops.map((f) => f[0] - f[1]).reduce((acc, sum) => acc + sum, 0);
};
console.log(
number([
[3, 0],
[9, 1],