Yomguithereal / mnemonist

Curated collection of data structures for the JavaScript/TypeScript language.
https://yomguithereal.github.io/mnemonist
MIT License
2.28k stars 92 forks source link

new method wanted: .has_prefix ? #207

Closed knutesears closed 1 year ago

knutesears commented 1 year ago

The .find method can be used to see if any words in the trie start with a certain prefix, but it becomes expensive if there are a lot of matches returned. The .has method already does the work needed, I think, but then always checks if the whole word exists. Perhaps rather than making a separate method, a second arg could be added to the .has method. Or perhaps the .has method could be a wrapper of a new .has_prefix method? In any case, it's a trivial change that would make this module more useful.

knutesears commented 1 year ago

Oooopps