Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions parser.rb
Original file line number Diff line number Diff line change
@@ -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