diff --git a/Gemfile b/Gemfile index 447683a..0b9c607 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,4 @@ source 'http://rubygems.org' gem 'rspec' gem 'pry' +gem 'facets' diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index b5cb288..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,30 +0,0 @@ -GEM - remote: http://rubygems.org/ - specs: - coderay (1.1.0) - diff-lcs (1.2.5) - method_source (0.8.2) - pry (0.10.0) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - rspec (3.1.0) - rspec-core (~> 3.1.0) - rspec-expectations (~> 3.1.0) - rspec-mocks (~> 3.1.0) - rspec-core (3.1.4) - rspec-support (~> 3.1.0) - rspec-expectations (3.1.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.1.0) - rspec-mocks (3.1.2) - rspec-support (~> 3.1.0) - rspec-support (3.1.1) - slop (3.5.0) - -PLATFORMS - ruby - -DEPENDENCIES - pry - rspec diff --git a/parser.rb b/parser.rb index 9396117..62613d6 100644 --- a/parser.rb +++ b/parser.rb @@ -1,13 +1,26 @@ require 'pry' +require 'facets' def kinda_like?(fuzzy_word, exact_word) - # implement with your code here - # breaking the method up into pieces is encouraged + end_letters_not_jumbled(fuzzy_word, exact_word) && + (is_exact_match(fuzzy_word, exact_word) || + at_most_one_letter_different(fuzzy_word, exact_word) ) end -#def another_private_method -#end +def is_exact_match(fuzzy_word, exact_word) + regex = Regexp.new(fuzzy_word) + !exact_word.match(regex).nil? +end + +def at_most_one_letter_different(fuzzy_word, exact_word) + extra_fuzzies = fuzzy_word.split(//).frequency - exact_word.split(//).frequency + extra_exacts = exact_word.split(//).frequency - fuzzy_word.split(//).frequency + extra_fuzzies.size < 2 && extra_exacts.size < 2 +end -#def some_private_method -#end +def end_letters_not_jumbled(fuzzy_word, exact_word) + p fuzzy_word[0] != exact_word[-1] + p fuzzy_word[-1] == exact_word[0] + fuzzy_word[0] != exact_word[-1] && fuzzy_word[-1] != exact_word[0] +end