| 8 | 8 | * @param {string} numberString |
| 9 | 9 | */ |
| 10 | 10 | constructor(numberString) { |
| 11 | throw new Error('Remove this line and implement the function'); | |
| 11 | // Edge Case: series cannot be empty | |
| 12 | if (numberString === '') { | |
| 13 | throw new Error('series cannot be empty'); | |
| 14 | } | |
| 15 | ||
| 16 | // Validate that input contains only 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; | |
| 12 | 23 | } |
| 13 | 24 | |
| 14 | 25 | /** |
| 16 | 27 | * @returns {number[][]} |
| 17 | 28 | */ |
| 18 | 29 | slices(sliceSize) { |
| 19 | throw new Error('Remove this line and implement the function'); | |
| 30 | // Edge Case: slice length cannot be negative | |
| 31 | if (sliceSize < 0) { | |
| 32 | throw new Error('slice length cannot be negative'); | |
| 33 | } | |
| 34 | ||
| 35 | // Edge Case: slice length cannot be zero | |
| 36 | if (sliceSize === 0) { | |
| 37 | throw new Error('slice length cannot be zero'); | |
| 38 | } | |
| 39 | ||
| 40 | // Edge Case: slice length cannot be 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 | for (let i = 0; i <= this.digits.length - sliceSize; i++) { | |
| 48 | result.push(this.digits.slice(i, i + sliceSize)); | |
| 49 | } | |
| 50 | ||
| 51 | return result; | |
| 20 | 52 | } |
| 21 | 53 | } |
| 54 | ||
| 55 | // Handled Edge Cases: series cannot be empty, slice length cannot be negative, slice length cannot be zero, slice length cannot be greater than series length |