mikedeboer/trie

getWords does not fully traverse tree

atlithorn opened this issue · 3 comments

Had two words in the trie:

week
weekend

trie.getWords('wee') only returns 'week'

I hacked getWords, removed the else in the for loop and it works fine for me

for (; i < l; ++i) {
    if (c[i].wordCount)
        words.push(s + c[i].stem);
    else
        words = words.concat(c[i].getWords(s + c[i].stem));
}

changed to:

for (; i < l; ++i) {
    if (c[i].wordCount)
        words.push(s + c[i].stem);
    words = words.concat(c[i].getWords(s + c[i].stem));
}

I reviewed your fix and I don't see a drawback for it :) have you - by any chance - written a test for this?

No but here's one:

var t = new Trie();
t.add('week');
t.add('weekend');
assert(t.getWords(t.find('wee')).length==2);

thanks! fixed and pushed to master.