Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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‎

Lines changed: 7 additions & 2 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /