tethys.backend/resources/js/Components/SimplePasswordMeter/logic/Trie.ts
Arno Kaimbacher 010bead723
Some checks failed
CI Pipeline / japa-tests (push) Failing after 1m0s
- add password strength meter for creating or editing user passwords
- add public opensearch api host
2024-08-07 14:22:36 +02:00

31 lines
717 B
TypeScript

import TrieNode from './TieNode';
export default class Trie {
private root: TrieNode;
constructor() {
this.root = new TrieNode();
}
insert(word: string) {
let node: TrieNode = this.root;
for (let char of word) {
if (!node.children[char]) {
node.children[char] = new TrieNode();
}
node = node.children[char];
}
node.isEndOfWord = true;
}
search(word: string) {
let node = this.root;
for (let char of word) {
if (!node.children[char]) {
return false;
}
node = node.children[char];
}
return node.isEndOfWord;
}
}