unicode

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 // Validate that all characters are digits
17 if (!/^[0-9]+$/.test(numberString)) {
18 throw new Error('series must contain only digits');
19 }
20
21 this.digits = numberString.split('').map(Number);
22 this.series = numberString;
1223 }
1324
1425 /**
15 * @param {number} sliceSize
16 * @returns {number[][]}
26 * Returns all contiguous substrings of the specified length from the series
27 * @param {number} sliceSize - The length of each substring to extract
28 * @returns {number[][]} - Array of arrays, each containing digits of a substring
29 * @throws {Error} - If sliceSize is invalid (negative, zero, or greater than series length)
1730 */
1831 slices(sliceSize) {
19 throw new Error('Remove this line and implement the function');
32 // Edge Case: Check if slice length is negative
33 if (sliceSize < 0) {
34 throw new Error('slice length cannot be negative');
35 }
36
37 // Edge Case: Check if slice length is zero
38 if (sliceSize === 0) {
39 throw new Error('slice length cannot be zero');
40 }
41
42 // Edge Case: Check if slice length is greater than series length
43 if (sliceSize > this.digits.length) {
44 throw new Error('slice length cannot be greater than series length');
45 }
46
47 const result = [];
48
49 // Edge Case: Handle when sliceSize equals the series length
50 if (sliceSize === this.digits.length) {
51 return [this.digits];
52 }
53
54 // Extract all contiguous substrings of the specified length
55 for (let i = 0; i <= this.digits.length - sliceSize; i++) {
56 result.push(this.digits.slice(i, i + sliceSize));
57 }
58
59 return result;
2060 }
2161}
62
63// Handled Edge Cases: Empty series, non-digit characters in series, negative slice length,
64// zero slice length, slice length greater than series length, slice length equals 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.