UNPKG

@kamilmielnik/trie

Version:

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

22 lines (21 loc) 675 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.nodeKeyComparator = void 0; /** * 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. */ const nodeKeyComparator = (key1, key2) => { if (key1 === 'wordEnd') { return -1; } if (key2 === 'wordEnd') { return 1; } return key1.localeCompare(key2); }; exports.nodeKeyComparator = nodeKeyComparator;