| 8 | 8 | * @returns {boolean} |
| 9 | 9 | */ |
| 10 | 10 | export const isIsogram = (string) => { |
| 11 | throw new Error('Remove this line and implement the function'); | |
| 11 | // Edge Case: Empty string is considered an isogram | |
| 12 | if (string.length === 0) { | |
| 13 | return true; | |
| 14 | } | |
| 15 | ||
| 16 | // Convert to lowercase to handle case insensitivity | |
| 17 | const lowerString = string.toLowerCase(); | |
| 18 | const seenLetters = new Set(); | |
| 19 | ||
| 20 | for (let i = 0; i < lowerString.length; i++) { | |
| 21 | const char = lowerString[i]; | |
| 22 | ||
| 23 | // Edge Case: Skip spaces and hyphens as they are allowed to repeat | |
| 24 | if (char === ' ' || char === '-') { | |
| 25 | continue; | |
| 26 | } | |
| 27 | ||
| 28 | // Edge Case: Check for repeated characters (including non-letters) | |
| 29 | if (seenLetters.has(char)) { | |
| 30 | return false; | |
| 31 | } | |
| 32 | ||
| 33 | seenLetters.add(char); | |
| 34 | } | |
| 35 | ||
| 36 | return true; | |
| 12 | 37 | }; |
| 38 | ||
| 39 | // Handled Edge Cases: empty string, case sensitivity, spaces, hyphens, non-letter characters, repeated letters |