Skip to content

Commit 9793691

Browse files
authored
Throw error for invalid argument
1 parent f920a4f commit 9793691

File tree

1 file changed

+4
-0
lines changed
  • src/_DataStructures_/Trees/Trie/get-unique-words

1 file changed

+4
-0
lines changed

src/_DataStructures_/Trees/Trie/get-unique-words/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Trie = require('../index');
2+
const TrieNode = require('../Node');
23

34
function getAllUniqueWords(root, level, word) {
45
let result = [];
@@ -24,6 +25,9 @@ function getAllUniqueWords(root, level, word) {
2425
}
2526

2627
function allUniqueWordsFromTrie(root) {
28+
if (!(root instanceof TrieNode)) {
29+
throw new Error('Invalid argument: Root of Trie is required');
30+
}
2731
const word = []; // char arr to store a word
2832
for (let i = 0; i < 26; i += 1) {
2933
word[i] = null;

0 commit comments

Comments
 (0)