Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions src/_DataStructures_/Trees/Trie/total-words-in-trie/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// eslint-disable-next-line no-unused-vars
const Trie = require('../index');

function totalWords(root) {
let result = 0;
if (root.isEndOfWord) {
Expand All @@ -14,10 +12,4 @@ function totalWords(root) {
return result;
}

// const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed'];
// const trie = new Trie();

// words.forEach(word => trie.insert(word));
// console.log(totalWords(trie.root));

module.exports = totalWords;
module.exports.totalWords = totalWords;
19 changes: 19 additions & 0 deletions src/_DataStructures_/Trees/Trie/total-words-in-trie/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const totalWordsInTrie = require('./index');
const Trie = require('../index');

describe('Trees Total words in trie', () => {
it('should return 6 when counting from trie object', () => {
const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed'];
const trie = new Trie();

words.forEach(word => trie.insert(word));

expect(totalWordsInTrie.totalWords(trie.root)).toEqual(words.length);
});

it('should return 0 when a empty Trie with no words inserted is created', () => {
const trie = new Trie();

expect(totalWordsInTrie.totalWords(trie.root)).toEqual(0);
});
});