* Step 1b: Handle -eed, -ed, -ing endings
(word: string)
| 94 | * Step 1b: Handle -eed, -ed, -ing endings |
| 95 | */ |
| 96 | function step1b(word: string): string { |
| 97 | if (word.endsWith("eed")) { |
| 98 | const stem = word.slice(0, -3); |
| 99 | if (hasMeasureGreaterThan0(stem)) { |
| 100 | return word.slice(0, -1); |
| 101 | } |
| 102 | return word; |
| 103 | } |
| 104 | |
| 105 | let stem = ""; |
| 106 | let suffix = ""; |
| 107 | |
| 108 | if (word.endsWith("ed")) { |
| 109 | stem = word.slice(0, -2); |
| 110 | suffix = "ed"; |
| 111 | } else if (word.endsWith("ing")) { |
| 112 | stem = word.slice(0, -3); |
| 113 | suffix = "ing"; |
| 114 | } |
| 115 | |
| 116 | if (suffix && containsVowel(stem)) { |
| 117 | word = stem; |
| 118 | |
| 119 | if (word.endsWith("at") || word.endsWith("bl") || word.endsWith("iz")) { |
| 120 | return word + "e"; |
| 121 | } |
| 122 | |
| 123 | if (endsWithDoubleConsonant(word)) { |
| 124 | const last = word[word.length - 1]!; |
| 125 | if (last !== "l" && last !== "s" && last !== "z") { |
| 126 | return word.slice(0, -1); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if (hasMeasureEqual1(word) && endsWithCVC(word)) { |
| 131 | return word + "e"; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | return word; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Step 1c: Handle -y endings |
no test coverage detected