agent

Finished
1//
2// This is only a SKELETON file for the 'Series' exercise. It's been provided as a
3// convenience to get you started writing code faster.
4//
5
61export class Series {
72 /**
8 * @param {string} numberString
3 * Creates a new Series instance from a string of digits
4 * @param {string} numberString - A string containing only digits
5 * @throws {Error} If the input string is empty
96 */
107 constructor(numberString) {
11 throw new Error('Remove this line and implement the function');
8 // Edge Case: Empty series input
9 if (numberString === '') {
10 throw new Error('series cannot be empty');
11 }
12
13 this.digits = numberString.split('').map(Number);
14
15 // Edge Case: Non-digit characters in the series
16 if (this.digits.includes(NaN)) {
17 throw new Error('series must contain only digits');
18 }
19
20 this.series = numberString;
1221 }
1322
1423 /**
15 * @param {number} sliceSize
16 * @returns {number[][]}
24 * Returns all contiguous substrings of the specified length from the series
25 * @param {number} sliceSize - The length of each substring to extract
26 * @returns {number[][]} An array of arrays, each containing the digits of a substring
27 * @throws {Error} If sliceSize is invalid (negative, zero, or greater than series length)
1728 */
1829 slices(sliceSize) {
19 throw new Error('Remove this line and implement the function');
30 // Edge Case: Negative slice length
31 if (sliceSize < 0) {
32 throw new Error('slice length cannot be negative');
33 }
34
35 // Edge Case: Zero slice length
36 if (sliceSize === 0) {
37 throw new Error('slice length cannot be zero');
38 }
39
40 // Edge Case: Slice length greater than series length
41 if (sliceSize > this.series.length) {
42 throw new Error('slice length cannot be greater than series length');
43 }
44
45 const result = [];
46
47 // Edge Case: Slice size equals series length
48 if (sliceSize === this.series.length) {
49 result.push(this.digits);
50 return result;
51 }
52
53 // Sliding window approach to extract all contiguous substrings
54 for (let i = 0; i <= this.digits.length - sliceSize; i++) {
55 result.push(this.digits.slice(i, i + sliceSize));
56 }
57
58 return result;
2059 }
60
61 // Handled Edge Cases: Empty series input, non-digit characters in series, negative slice length, zero slice length, slice length greater than series length, slice size equals series length
2162}
63
64// Handled Edge Cases: Empty series input, non-digit characters in series, negative slice length, zero slice length, slice length greater than series length, slice size 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.