-
Notifications
You must be signed in to change notification settings - Fork 0
/
kata.js
47 lines (28 loc) · 944 Bytes
/
kata.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
function getLengthOfMissingArray(arrayOfArrays) {
const l = (arrayOfArrays || [])
.map(a => a ? a.length : 0)
.sort((a, b) => a - b)
if (l.includes(0)) {
return 0
}
for (let i = 0; i < l.length - 1; i++) {
if (l[i] + 1 !== l[i + 1]) {
return l[i] + 1
}
}
return 0
}
console.log(getLengthOfMissingArray([[4], [4, 4, 3, 1], [], [1, 0, 0]]));
// 0
console.log(getLengthOfMissingArray([[], [0, 2], [2, 1, 0]]));
// 0
console.log(getLengthOfMissingArray([[1, 2], [4, 5, 1, 1], [1], [5, 6, 7, 8, 9]]));
// 3
console.log(getLengthOfMissingArray([[5, 2, 9], [4, 5, 1, 1], [1], [5, 6, 7, 8, 9]]));
// 2
console.log(getLengthOfMissingArray([[null], [null, null, null]]));
// 2
console.log(getLengthOfMissingArray([['a', 'a', 'a'], ['a', 'a'], ['a', 'a', 'a', 'a'], ['a'], ['a', 'a', 'a', 'a', 'a', 'a']]));
// 5
console.log(getLengthOfMissingArray([]));
// 0