Created
January 13, 2023 17:48
-
-
Save deleteman/05bbfd8988f097d742222678f23050e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createTree(tree) { | |
let ret = findPrefixes(suffixes) | |
suffixes = removeWordsFromList(ret.usedWords, suffixes) | |
root = ret.group.shift() | |
tree[root] = {pending: ret.group} | |
while(tree[root].pending.length > 0) { | |
ret = findPrefixes(tree[root].pending) | |
if(ret.group.length == 1) { //it's a leaf | |
tree[root][ret.group[0]] = "*" | |
} else { | |
tree[root][ret.group[0]] = {} | |
ret.group.slice(1).forEach( w => { | |
tree[root][ret.group[0]][w] = "*" | |
}) | |
} | |
tree[root].pending = removeWordsFromList(ret.usedWords, tree[root].pending) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment