- [ ] cd into your cloned repo, bundle install and run observr test/observr to get started.
- [ ] As you get each test passing, remove the line skip from the next test.
- [ ] Complete the first five tests in test/test_green_eggs_and_ham.rb.
Bonus
- [ ] Complete the last two tests. Their solutions are very simple, but might be a little tricky to figure out.
Hints
The some of the tests expect words to be lowercase, but not all of the words in the text are lower case. Some of the words also end in punctuation that should be excluded when checking for unique words, i.e. "Sam-I-am!", "Sam-I-am", and "sam-i-am" should all be considered the same word.
Here's how to normalize them:
word = "Sam-I-am!"
word.downcase.gsub(/[^a-z-]/, '') # => "sam-i-am"
We'll talk about Regular Expressions soon, that's what the /[^a-z-]/ is (it matches all characters that are not "a" through "z" or "-"). Feel free to research if you want, but this is a freebie.
Week 3 - Assignment 4
Description
This assignment serves to reinforce Ruby syntax and usage of blocks and enumerable with arrays and hashes. You'll also dabble in String manipulation.
After completing this assignment, you should:
Enumerable
like:map
,select
,reject
,max_by
andsort
.Array
like:uniq
andeach
.String
like:split
,lines
andgsub
.observr
to automatically run your tests.Details
cd
into your cloned repo,bundle install
and runobservr test/observr
to get started.skip
from the next test.test/test_green_eggs_and_ham.rb
.Bonus
Hints
The some of the tests expect words to be lowercase, but not all of the words in the text are lower case. Some of the words also end in punctuation that should be excluded when checking for unique words, i.e. "Sam-I-am!", "Sam-I-am", and "sam-i-am" should all be considered the same word.
Here's how to normalize them:
We'll talk about Regular Expressions soon, that's what the
/[^a-z-]/
is (it matches all characters that are not "a" through "z" or "-"). Feel free to research if you want, but this is a freebie.Resources