We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a0e0fd8 commit 524670eCopy full SHA for 524670e
src/data-structures/trees/trie.js
@@ -65,17 +65,18 @@ class Trie {
65
*
66
* @param {string} prefix - The prefix to append to each word.
67
* @param {string} node - Current node to start backtracking.
68
- * @param {string[]} words - Accumulated words.
69
- * @param {string} string - Current string.
70
*/
71
- getAllWords(prefix = '', node = this, words = [], string = '') {
+ getAllWords(prefix = '', node = this) {
+ let words = [];
+
72
if (!node) { return words; }
73
if (node.isWord) {
74
- words.push(`${prefix}${string}`);
+ words.push(prefix);
75
}
76
77
for (const char of Object.keys(node.children)) {
78
- this.getAllWords(prefix, node.children[char], words, `${string}${char}`);
+ const newWords = this.getAllWords(`${prefix}${char}`, node.children[char]);
79
+ words = words.concat(newWords);
80
81
82
return words;
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments