UNPKG

@kamilmielnik/trie

Version:

Trie data structure implementation in TypeScript. Highly performant. No dependencies. Built for a Scrabble Solver.

23 lines (22 loc) 703 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.find = void 0; /** * Finds {@link Node} representing given prefix in given {@link Node}. * * @param node - {@link Node} to look for prefix in. * @param prefix - Prefix to be found. * @returns {@link Node} representing a given prefix, undefined if there is no such node. */ const find = (node, prefix) => { let currentNode = node; for (let index = 0; index < prefix.length; ++index) { const character = prefix[index]; if (!currentNode[character]) { return undefined; } currentNode = currentNode[character]; } return currentNode; }; exports.find = find;