Skip to content

Commit 2fbc809

Browse files
committed
fix: return words based on wordCount
1 parent f0ca6ed commit 2fbc809

File tree

1 file changed

+7
-2
lines changed
  • src/_DataStructures_/Trees/Trie/all-words-in-trie

1 file changed

+7
-2
lines changed

src/_DataStructures_/Trees/Trie/all-words-in-trie/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ function getAllWords(root, level, word) {
1111
for (let i = 0; i < level; i += 1) {
1212
temp += String(word[i]);
1313
}
14-
result = [...result, temp];
14+
// get the count and push all the occurences
15+
const res = [];
16+
for (let i = 0; i < root.wordCount; i += 1) {
17+
res.push(temp);
18+
}
19+
result = [...result, ...res];
1520
}
1621

1722
for (let i = 0; i < 26; i += 1) {
@@ -32,7 +37,7 @@ function allWordsFromTrie(root) {
3237
return getAllWords(root, 0, word);
3338
}
3439

35-
// const words = ['bed', 'ball', 'apple', 'java', 'javascript'];
40+
// const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed'];
3641
// const trie = new Trie();
3742

3843
// words.forEach(word => trie.insert(word));

0 commit comments

Comments
 (0)