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
31 changes: 25 additions & 6 deletions parser.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
require 'pry'

def kinda_like?(fuzzy_word, exact_word)
# implement with your code here
# breaking the method up into pieces is encouraged
fuzzy_chars = fuzzy_word.chars
exact_chars = exact_word.chars

a = diff(fuzzy_chars.dup, exact_chars.dup)
b = diff(exact_chars.dup, fuzzy_chars.dup)

(
(a > 1) ||
(b > 1) ||
end_letters_switched?(fuzzy_word, exact_word)
) ? false : true
end

#def another_private_method
#end
def diff(a, b)
a.each do |char|
if (index = b.find_index char)
b.delete_at index
end
end
b.size
end

#def some_private_method
#end
def end_letters_switched?(a, b)
first = ->(a) { a.chars.first }
last = ->(a) { a.chars.last }
c = b.reverse
first.(a) == first.(c) && last.(a) == last.(c)
end