File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
src/data-structures/trees Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -65,17 +65,18 @@ class Trie {
65
65
*
66
66
* @param {string} prefix - The prefix to append to each word.
67
67
* @param {string} node - Current node to start backtracking.
68
- * @param {string[]} words - Accumulated words.
69
- * @param {string} string - Current string.
70
68
*/
71
- getAllWords(prefix = '', node = this, words = [], string = '') {
69
+ getAllWords(prefix = '', node = this) {
70
+ let words = [];
71
+
72
72
if (!node) { return words; }
73
73
if (node.isWord) {
74
- words.push(`${ prefix}${string}` );
74
+ words.push(prefix);
75
75
}
76
76
77
77
for (const char of Object.keys(node.children)) {
78
- this.getAllWords(prefix, node.children[char], words, `${string}${char}`);
78
+ const newWords = this.getAllWords(`${prefix}${char}`, node.children[char]);
79
+ words = words.concat(newWords);
79
80
}
80
81
81
82
return words;
You can’t perform that action at this time.
0 commit comments