joseph

Finished
88 * @param {string} numberString
99 */
1010 constructor(numberString) {
11 throw new Error('Remove this line and implement the function');
11 // Edge Case: Check if the input string is empty
12 if (numberString === '') {
13 throw new Error('series cannot be empty');
14 }
15
16 this.numberString = numberString;
1217 }
1318
1419 /**
1621 * @returns {number[][]}
1722 */
1823 slices(sliceSize) {
19 throw new Error('Remove this line and implement the function');
24 // Edge Case: Check if slice length is negative
25 if (sliceSize < 0) {
26 throw new Error('slice length cannot be negative');
27 }
28
29 // Edge Case: Check if slice length is zero
30 if (sliceSize === 0) {
31 throw new Error('slice length cannot be zero');
32 }
33
34 // Edge Case: Check if slice length is greater than series length
35 if (sliceSize > this.numberString.length) {
36 throw new Error('slice length cannot be greater than series length');
37 }
38
39 const result = [];
40
41 // Use sliding window to extract all contiguous substrings
42 for (let i = 0; i <= this.numberString.length - sliceSize; i++) {
43 const substring = this.numberString.substring(i, i + sliceSize);
44 const digits = substring.split('').map(char => parseInt(char, 10));
45 result.push(digits);
46 }
47
48 return result;
2049 }
2150}
51
52// Handled Edge Cases: empty series, negative slice length, zero slice length, slice length greater than series length
Test NameStatus
slices of one from one
Pass
slices of one from two
Pass
slices of two
Pass
slices of two overlap
Pass
slices can include duplicates
Pass
slices of long series
Pass
slice length is too large
Pass
slice length is way too large
Pass
slice length cannot be zero
Pass
slice length cannot be negative
Pass
empty series is invalid
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.