Answers for "String#count_sentences returns the number of sentences in a complex string Failure/Error: expect(complex_string.count_sentences).to eq(4)"

0

String#count_sentences returns the number of sentences in a complex string Failure/Error: expect(complex_string.count_sentences).to eq(4)

class String
  def count_sentences
    scan(/[.!?]+(?=\s|\z)/).size
  end
end

str = "Learning Ruby is great!!!! The course cost $2.43... How much??!"

str.count_sentences
  #=> 3
Posted by: Guest on January-10-2020

Code answers related to "String#count_sentences returns the number of sentences in a complex string Failure/Error: expect(complex_string.count_sentences).to eq(4)"

Browse Popular Code Answers by Language