Last active
August 29, 2015 14:03
-
-
Save Ignas/0d94ea2d63f3d52cef30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
indices = [candidate.index(/\b#{this_query_char}/), | |
candidate.index(this_query_char)] | |
scores = [1, indices[1] + 1] | |
indices.zip(scores).map { |index, score_delta| | |
if index | |
candidate_remainder = candidate[(index + 1)..-1] | |
score = score_substring(candidate_remainder, query_remainder) | |
if score | |
score + score_delta | |
end | |
end | |
}.compact.min | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment