diff --git a/parser.rb b/parser.rb index 9396117..e2f6a7e 100644 --- a/parser.rb +++ b/parser.rb @@ -1,13 +1,21 @@ require 'pry' def kinda_like?(fuzzy_word, exact_word) - # implement with your code here - # breaking the method up into pieces is encouraged + diff_count(fuzzy_word, exact_word) < 2 and !ends_jumbled?(fuzzy_word, exact_word) end -#def another_private_method -#end +private -#def some_private_method -#end +def diff_count(fuzzy_word, exact_word) + [fuzzy_word.length, exact_word.length].max - match_count(fuzzy_word, exact_word) +end + +def match_count(fuzzy_word, exact_word) + fuzzy_word.chars.uniq.inject(0) do |memo, char| + memo += [fuzzy_word.count(char), exact_word.count(char)].min + end +end +def ends_jumbled?(fuzzy_word, exact_word) + fuzzy_word[0] == exact_word[-1] and fuzzy_word[-1] == exact_word[0] +end