Exercise Tuesday

Goal: Your goal is to continue practicing TDD and Ruby syntax and to write tests before your code. You should no longer define methods in main. Your logic should include custom classes with instance methods. All methods should be called on instances of a class.

Warm Up

  • What is a key-value pair? What does a key represent? How about the value?
  • When might we use a hash? What's the difference between a Hash and an Array?


Scrabble Score

Write a method that takes a word and returns the Scrabble score for that word. Here are the values of letters in Scrabble:

A, E, I, O, U, L, N, R, S, T       1
D, G                               2
B, C, M, P                         3
F, H, V, W, Y                      4
K                                  5
J, X                               8
Q, Z                               10

Here is a spec to get you started:

it("returns a scrabble score for a letter") do

Numbers to Words

Write a method that translates numbers in numeric form into written words. For example, it would translate 384 into "three hundred eighty four". Use multiple hashes and the .fetch() method to solve this.

Start small, and then get your code working for numbers up to 1 trillion.

Further Exploration

If you've fully completed both projects listed above with time to spare, focus on the following:

  • Add additional code to your translator to take words and translate them into numbers.

  • Create a document parser that determines the total Scrabble score of all the words in the document. You should use built-in Ruby methods like File.open() and File.close() and then parse the document.

  • Create a document parser that compares two documents and checks which one has a higher Scrabble score. Or, if you’d like to practice building something more practical, build a parser that checks to see if two documents have the same content.

Peer Code Review

  • Do specs have complete coverage for the behaviors that need to be tested?
  • Does application use custom classes to store instance methods and instance variables?
  • Are specs passing? Is there anything you could pass into their method(s) that isn't anticipated by at least one test? If so, how would they test for this?
  • Is logic easy to understand? Could it be further refactored? Explain.
  • Does code have proper indentation and spacing throughout?
  • Are variable names descriptive?

Lesson 10 of 22
Last updated more than 3 months ago.