Enumerables2_spec.rb

asks

Define a method that accepts a string of lower case words (no punctuation) and

returns an array of letters that occur more than once, sorted alphabetically.

However the answers at the end of the section provides
"def non_unique_letters(string)
characters = string.chars.uniq
characters.delete(" “)
characters.select { |char| string.count(char) > 1 }
end"
as a correct response. However it should read
” characters.sort.select { |char| string.count(char) > 1 } "

1 Like

Test case for the above problem doesn’t test for sorted, and also the following problem “longest_two_words” does not test for punctuation removal which it does request you implement.
The first test case does not request that it return 0 if an empty array is given. also: The first test case solution fails to pass the spec tests for this reason.

1 Like

Hello Nicholas!
I agree that the solution for the non_unique_letter should have the sort method.

For the longest two words problem, it always good to have the edge cases. However, the solution that they provided pass the rspec for the longest_two_words unless you talking about the test for an empty [string] array, which is not in the rspec.

 **Solution:**

 def longest_two_words(string)
 # string.split.sort_by(&:length)[-2,2].sort   <--- my version, below is the solution
   string.delete!(",.;:!?")
   string.split.sort_by {|word| word.length}[-2..-1]
 end


**enumerables2_spec.rb**

describe "longest_two_words" do
   let(:string) { "this is a string with sooooooo many words" }

   it "returns two words" do
    expect(longest_two_words(string).length).to be(2)
   end

   it "returns the longest words" do
     two_words = ["sooooooo", "string"]
     expect(longest_two_words(string).sort).to eq(two_words)
   end
end

  **Pass the Rspec test, test on terminal**
  YoungNguyens-MacBook-Pro:enumerable exercises YoungNguyen$ bundle exec rspec -c
  ..................................

  Finished in 0.01286 seconds (files took 0.1011 seconds to load)
  34 examples, 0 failures