| 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: empty input string | |
| 12 | if (numberString === '') { | |
| 13 | throw new Error('series cannot be empty'); | |
| 14 | } | |
| 15 | ||
| 16 | // Edge Case: non-digit characters in string | |
| 17 | if (!/^\d+$/.test(numberString)) { | |
| 18 | throw new Error('series must contain only digits'); | |
| 19 | } | |
| 20 | ||
| 21 | this.digits = numberString.split('').map(Number); | |
| 12 | 22 | } |
| 13 | 23 | |
| 14 | 24 | /** |
| 16 | 26 | * @returns {number[][]} |
| 17 | 27 | */ |
| 18 | 28 | slices(sliceSize) { |
| 19 | throw new Error('Remove this line and implement the function'); | |
| 29 | // Edge Case: negative slice length | |
| 30 | if (sliceSize < 0) { | |
| 31 | throw new Error('slice length cannot be negative'); | |
| 32 | } | |
| 33 | ||
| 34 | // Edge Case: zero slice length | |
| 35 | if (sliceSize === 0) { | |
| 36 | throw new Error('slice length cannot be zero'); | |
| 37 | } | |
| 38 | ||
| 39 | // Edge Case: slice length greater than string length | |
| 40 | if (sliceSize > this.digits.length) { | |
| 41 | throw new Error('slice length cannot be greater than series length'); | |
| 42 | } | |
| 43 | ||
| 44 | const result = []; | |
| 45 | ||
| 46 | // Edge Case: slice length equal to string length | |
| 47 | if (sliceSize === this.digits.length) { | |
| 48 | result.push([...this.digits]); | |
| 49 | return result; | |
| 50 | } | |
| 51 | ||
| 52 | // Edge Case: single character string with slice length of 1 | |
| 53 | for (let i = 0; i <= this.digits.length - sliceSize; i++) { | |
| 54 | result.push(this.digits.slice(i, i + sliceSize)); | |
| 55 | } | |
| 56 | ||
| 57 | return result; | |
| 20 | 58 | } |
| 21 | 59 | } |
| 60 | ||
| 61 | // Handled Edge Cases: empty input string, non-digit characters in string, negative slice length, zero slice length, slice length greater than string length, slice length equal to string length, single character string with slice length of 1 |