UNPKG

@kamilmielnik/trie

Version:

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

18 lines (17 loc) 522 B
/** * Comparator that allows sorting {@link Node} keys alphabetically * with the exception of "wordEnd" which should always come first. * * @param key1 - First key to compare. * @param key2 - Second key to compare. * @returns -1 if key1 should precede key2, 0 if they're the same, 1 if key2 should precede key1. */ export const nodeKeyComparator = (key1, key2) => { if (key1 === 'wordEnd') { return -1; } if (key2 === 'wordEnd') { return 1; } return key1.localeCompare(key2); };