Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function to return index #12

Closed
wants to merge 3 commits into from
Closed

Conversation

yktakaha4
Copy link

Thanks for the great library!

I thought it would be more flexible to add a function that returns the index of the array (e.g., to use the value of the object corresponding to index)

I have already created a test and confirmed that it does not break the existing behavior.

@BeLi4L
Copy link

BeLi4L commented Dec 17, 2020

I personally feel like this kind of utility methods doesn't really belong in such a library, which is focused on the distance itself, not a specific use-case related to that distance.

I'm not sure why closest was added in the first place 🤷

@ka-weihe
Copy link
Owner

I thought it would be more flexible to add a function that returns the index of the array (e.g., to use the value of the object corresponding to index)

@yktakaha4 I agree, that is probably how closest should have been, but I don't think I will add your changes now (but thank you, I will maybe open this again later). I have to think about it. For now, you just have to do it in your own code.

I'm not sure why closest was added in the first place

@BeLi4L closest was added because it is possible to do some very powerful optimizations when you compute the distance between one string and an array of multiple strings. I have not added these optimizations yet, but that is why closest is in the source. closest is also how this package is mostly used by people.

@BeLi4L
Copy link

BeLi4L commented Dec 17, 2020

@BeLi4L closest was added because it is possible to do some very powerful optimizations when you compute the distance between one string and an array of multiple strings

Good point! I didn't think of that 👍

Just curious, since I only use distance, do you have examples of use cases of closest? 🤔

@ka-weihe
Copy link
Owner

ka-weihe commented Dec 17, 2020

Just curious, since I only use distance, do you have examples of use cases of closest?

Imagine you have an array of all english words and a misspelled word.

Then you would simply do ...

closest(misspelled_word, all_english_words)

... to find the correct word.

@ka-weihe ka-weihe closed this Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants