A.2.1

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 // Edge Case: Empty series input
14 if (!numberString) {
15 throw new Error('series cannot be empty');
16 }
17
18 // Edge Case: Series contains non-digit characters
19 if (!/^[0-9]+$/.test(numberString)) {
20 throw new Error('series must contain only digits');
21 }
22
23 this.digits = numberString.split('').map(Number);
24
25 // Handled Edge Cases: Empty series input, series with non-digit characters
1226 }
1327
1428 /**
15 * @param {number} sliceSize
16 * @returns {number[][]}
29 * Returns all contiguous substrings of the specified length from the series
30 * @param {number} sliceSize - The length of each substring to extract
31 * @returns {number[][]} An array of arrays, each containing digits of a substring
32 * @throws {Error} If sliceSize is invalid (negative, zero, or greater than series length)
1733 */
1834 slices(sliceSize) {
19 throw new Error('Remove this line and implement the function');
35 // Edge Case: Negative slice length
36 if (sliceSize < 0) {
37 throw new Error('slice length cannot be negative');
38 }
39
40 // Edge Case: Zero slice length
41 if (sliceSize === 0) {
42 throw new Error('slice length cannot be zero');
43 }
44
45 // Edge Case: Slice length greater than series length
46 if (sliceSize > this.digits.length) {
47 throw new Error('slice length cannot be greater than series length');
48 }
49
50 const result = [];
51
52 // Edge Case: Slice size equals series length (only one slice possible)
53 if (sliceSize === this.digits.length) {
54 result.push([...this.digits]);
55 return result;
56 }
57
58 // Sliding window approach to extract all contiguous substrings
59 for (let i = 0; i <= this.digits.length - sliceSize; i++) {
60 const slice = this.digits.slice(i, i + sliceSize);
61 result.push(slice);
62 }
63
64 return result;
65
66 // Handled Edge Cases: Negative slice length, zero slice length, slice length greater than series length, slice size equals series length
2067 }
2168}
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.