react-typeahead
react-typeahead copied to clipboard
Sort results by relevance, not alphabetical order
Is there a way to sort results by relevance.
For example, if or options list is ['Canada', 'Abacan', 'Bolcan']. I type "Can" and see:
Abacan
Bolcan
Canada
But "Canada" is the most relevant result, because it starts with our inputValue.
I have a sort function to handle it:
arr.sort((a, b) => {
if (a.indexOf(inputValue) > b.indexOf(inputValue)) return 1;
else if (a.indexOf(inputValue) < b.indexOf(inputValue)) return -1;
else return 0;
})
How can I implement it?
:+1: