Skip to content

Commit 540a6e2

Browse files
authored
getNodesWithAdd
1 parent 7792b5c commit 540a6e2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

colors/try-hard.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,25 @@ export function getNodesWithDelete(root, word) {
166166
return all.sort((a, b) => b.length - a.length);
167167
}
168168

169+
/**
170+
* Adds a wildcard between each character in the word so that single character errors can be found
171+
* @param { LetterNode } root
172+
* @param { string } word
173+
*/
174+
export function getNodesWithAdd(root, word) {
175+
const all = [];
176+
for (let index = 0; index < word.length; ++index) {
177+
const replacement = word.substring(0, index) + wildcard + word.substring(index);
178+
const results = getNodesWithWildcards(root, replacement);
179+
for (const result of results) {
180+
if (result.length > index) { // Ignore results unaffected by the replacement
181+
all.push(result);
182+
}
183+
}
184+
}
185+
return all.sort((a, b) => b.length - a.length);
186+
}
187+
169188
/**
170189
* Swaps pairs of letters so that single pair swaps can be found
171190
* (Doesn't require wildcards)

0 commit comments

Comments
 (0)