@kamilmielnik/trie
Version:
Trie data structure implementation in TypeScript. Highly performant. No dependencies. Built for a Scrabble Solver.
15 lines (14 loc) • 537 B
JavaScript
import { find } from './find.js';
/**
* Tells you whether there are any words with given prefix in the {@link Node}.
*
* See: https://en.wikipedia.org/wiki/String_operations#Prefixes
*
* @param node - {@link Node} to look for prefix in.
* @param prefix - Prefix to be found.
* @returns true if there are any words with given prefix in the {@link Node}, false otherwise.
*/
export const hasPrefix = (node, prefix) => {
const foundNode = find(node, prefix);
return foundNode ? Object.keys(foundNode).length > 0 : false;
};