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 {
6565 *
6666 * @param {string } prefix - The prefix to append to each word.
6767 * @param {string } node - Current node to start backtracking.
68- * @param {string[] } words - Accumulated words.
69- * @param {string } string - Current string.
7068 */
71- getAllWords ( prefix = '' , node = this , words = [ ] , string = '' ) {
69+ getAllWords ( prefix = '' , node = this ) {
70+ let words = [ ] ;
71+
7272 if ( ! node ) { return words ; }
7373 if ( node . isWord ) {
74- words . push ( ` ${ prefix } ${ string } ` ) ;
74+ words . push ( prefix ) ;
7575 }
7676
7777 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 ) ;
7980 }
8081
8182 return words ;
You can’t perform that action at this time.
0 commit comments