Sort results By indexOf() of the input #5534
Unanswered
omerbarda130
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Im trying to understand how can i sort the options by the index of the input the user typed
for example:
the all options are: Thai, Sanskrit, Italian
and the user typed: "it"
the result should be: Italian, Sanskrit
because the indexOf "it" in Italian is lower then the indexOf "it" in Sanskrit.
the Thai does not contains "it" at all so he will disappear
result.sort((a,b)=>{a.indexOf(input)-b.indexOf(input)})
Beta Was this translation helpful? Give feedback.
All reactions