Skip to content

Commit 7c5ad25

Browse files
committed
removes a redundant condition
1 parent 8e653a4 commit 7c5ad25

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

chapters/ch07-ex-implementing-a-trie.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,14 @@ class TrieNode {
234234

235235
class Trie {
236236
constructor() {
237-
// The root node is an empty TrieNode.
238237
this.root = new TrieNode();
239238
}
240239

241240
insert(word, node = this.root) {
242241
const wordLength = word.length;
243242
if (wordLength === 0) return;
244243

245-
// Iterate over each character in the word.
246244
for (let idx = 0; idx < wordLength; idx++) {
247-
// Get the current character.
248245
let char = word[idx];
249246

250247
// Check if the current node has a child node for the current character.
@@ -255,12 +252,9 @@ class Trie {
255252

256253
// Move to the child node corresponding to the current character.
257254
node = node.children.get(char);
258-
259-
// If this is the last character of the word, mark the node as the end of a word.
260-
if (idx === word.length - 1) {
261-
node.isEndOfWord = true;
262-
}
263255
}
256+
257+
node.isEndOfWord = true;
264258
}
265259
}
266260
```

0 commit comments

Comments
 (0)