From fbb8f215fcec6f0760fb14ff76ae8fda20886df3 Mon Sep 17 00:00:00 2001 From: Samuel Priddy Date: Fri, 11 Dec 2015 16:05:32 -0500 Subject: [PATCH 1/5] Write names in for empty methods --- parser.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/parser.rb b/parser.rb index 9396117..0254604 100644 --- a/parser.rb +++ b/parser.rb @@ -5,9 +5,13 @@ def kinda_like?(fuzzy_word, exact_word) # breaking the method up into pieces is encouraged end -#def another_private_method -#end +private -#def some_private_method -#end +def letter_differences(fuzzy_word, exact_word) + +end + +def jumble_type + +end From deace71818169f7deb25b12b9dad49bc696fa550 Mon Sep 17 00:00:00 2001 From: Samuel Priddy Date: Fri, 11 Dec 2015 17:03:18 -0500 Subject: [PATCH 2/5] Initial solution --- parser.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/parser.rb b/parser.rb index 0254604..977b7e3 100644 --- a/parser.rb +++ b/parser.rb @@ -1,17 +1,31 @@ require 'pry' def kinda_like?(fuzzy_word, exact_word) - # implement with your code here - # breaking the method up into pieces is encouraged + return false if ends_jumbled?(fuzzy_word, exact_word) + + case letter_differences(fuzzy_word, exact_word) + when 0..1 then true + else false + end end private def letter_differences(fuzzy_word, exact_word) + common_characters = fuzzy_word.chars & exact_word.chars -end + number_of_matches = 0 + common_characters.each do |char| + number_of_matches += [fuzzy_word.count(char), exact_word.count(char)].min + end -def jumble_type + [fuzzy_word.length, exact_word.length].max - number_of_matches +end +def ends_jumbled?(fuzzy_word, exact_word) + fuzzy_word[0] == exact_word[-1] and fuzzy_word[-1] == exact_word[0] end +# dejumble the middle first +# then compare differences +# if differences is more than From 336f1d32cddd5d0ccf7f79ec36c5ed1c90957caa Mon Sep 17 00:00:00 2001 From: Samuel Priddy Date: Fri, 11 Dec 2015 17:18:36 -0500 Subject: [PATCH 3/5] Refactor kinda_like? to be less verbose --- parser.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/parser.rb b/parser.rb index 977b7e3..61a8ee6 100644 --- a/parser.rb +++ b/parser.rb @@ -1,21 +1,16 @@ require 'pry' def kinda_like?(fuzzy_word, exact_word) - return false if ends_jumbled?(fuzzy_word, exact_word) - - case letter_differences(fuzzy_word, exact_word) - when 0..1 then true - else false - end + diff_count(fuzzy_word, exact_word) < 2 and !ends_jumbled?(fuzzy_word, exact_word) end private -def letter_differences(fuzzy_word, exact_word) - common_characters = fuzzy_word.chars & exact_word.chars +def diff_count(fuzzy_word, exact_word) + common_chars = fuzzy_word.chars & exact_word.chars number_of_matches = 0 - common_characters.each do |char| + common_chars.each do |char| number_of_matches += [fuzzy_word.count(char), exact_word.count(char)].min end From 638d9e1573602ca49372c85c19e2e112a89742e7 Mon Sep 17 00:00:00 2001 From: Samuel Priddy Date: Fri, 11 Dec 2015 17:19:07 -0500 Subject: [PATCH 4/5] Remove unneeded comments at bottom' --- parser.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/parser.rb b/parser.rb index 61a8ee6..e444970 100644 --- a/parser.rb +++ b/parser.rb @@ -20,7 +20,3 @@ def diff_count(fuzzy_word, exact_word) def ends_jumbled?(fuzzy_word, exact_word) fuzzy_word[0] == exact_word[-1] and fuzzy_word[-1] == exact_word[0] end - -# dejumble the middle first -# then compare differences -# if differences is more than From d69a2abfe698315c377fdc285370c84eb3988fce Mon Sep 17 00:00:00 2001 From: Samuel Priddy Date: Sun, 13 Dec 2015 16:17:20 -0500 Subject: [PATCH 5/5] Move match counting responsibility into own function --- parser.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/parser.rb b/parser.rb index e444970..e2f6a7e 100644 --- a/parser.rb +++ b/parser.rb @@ -7,14 +7,13 @@ def kinda_like?(fuzzy_word, exact_word) private def diff_count(fuzzy_word, exact_word) - common_chars = fuzzy_word.chars & exact_word.chars + [fuzzy_word.length, exact_word.length].max - match_count(fuzzy_word, exact_word) +end - number_of_matches = 0 - common_chars.each do |char| - number_of_matches += [fuzzy_word.count(char), exact_word.count(char)].min +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 - - [fuzzy_word.length, exact_word.length].max - number_of_matches end def ends_jumbled?(fuzzy_word, exact_word)