Skip to content

Commit a6b3ce7

Browse files
committed
update: counting word ocurences
1 parent 6469d5f commit a6b3ce7

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/_DataStructures_/Trees/Trie/Node.js

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class TrieNode {
33
this.char = char;
44
this.children = [];
55
this.isEndOfWord = false;
6+
this.wordCount = 0;
67

78
// mark all the alphabets as null
89
for (let i = 0; i < 26; i += 1) this.children[i] = null;
@@ -15,6 +16,10 @@ class TrieNode {
1516
unmarkAsLeaf() {
1617
this.isEndOfWord = false;
1718
}
19+
20+
increaseCount() {
21+
this.wordCount += 1;
22+
}
1823
}
1924

2025
module.exports = TrieNode;

src/_DataStructures_/Trees/Trie/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Trie {
3232
// when we are done with inserting all the character of the word,
3333
// mark the node as end leaf
3434
currentNode.markAsLeaf();
35+
currentNode.increaseCount();
3536
return true;
3637
}
3738

0 commit comments

Comments
 (0)