Konoha

Finished
55
66export class Series {
77 /**
8 * @param {string} numberString
8 * Creates a new Series instance from a string of digits
9 * @param {string} numberString - A string containing only digits
10 * @throws {Error} If the input string is empty
911 */
1012 constructor(numberString) {
11 throw new Error('Remove this line and implement the function');
13 this.digits = numberString.split('').map(Number);
1214 }
1315
1416 /**
15 * @param {number} sliceSize
16 * @returns {number[][]}
17 * Returns all contiguous substrings of the specified length from the series
18 * @param {number} sliceSize - The length of each substring to extract
19 * @returns {number[][]} An array of arrays, each containing digits of a substring
20 * @throws {Error} If sliceSize is invalid (negative, zero, or greater than series length)
1721 */
1822 slices(sliceSize) {
19 throw new Error('Remove this line and implement the function');
23 // Edge Case: Negative slice length (takes precedence over all other checks)
24 if (sliceSize < 0) {
25 throw new Error('slice length cannot be negative');
26 }
27
28 // Edge Case: Zero slice length (takes precedence over empty series check)
29 if (sliceSize === 0) {
30 throw new Error('slice length cannot be zero');
31 }
32
33 // Edge Case: Empty series (only checked after slice length validation)
34 if (this.digits.length === 0) {
35 throw new Error('series cannot be empty');
36 }
37
38 // Edge Case: Slice length greater than series length
39 if (sliceSize > this.digits.length) {
40 throw new Error('slice length cannot be greater than series length');
41 }
42
43 const result = [];
44
45 for (let i = 0; i <= this.digits.length - sliceSize; i++) {
46 result.push(this.digits.slice(i, i + sliceSize));
47 }
48
49 return result;
2050 }
2151}
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.