Exercise

Goal: Build out the text-analyzer application, making sure to practice TDD, good separation of logic, and DRY code. Keep in mind that separating logic and DRYing up code take a lot of practice, especially at first. Sometimes it's a struggle just to get your code working, let alone keeping it DRY. However, if you apply TDD and separate your logic, you will find the problem solving process easier and you'll also have an easier time fixing bugs.

Warm Up


  • What is TDD? How can it help us solve problems?
  • What is separation of logic? Why is it important?
  • What does DRY mean? What are some reasons to DRY our code?

Code


Text Analyzer Update

At this point, you should've followed along with the lessons to build a small Text Analyzer application. Now it's time to add some more code!

  • Write a function that returns the three most used words in a passage of text. For instance, this string: "Hi there hey yo hi hi yay yo whoa there whoa... yay!" would return:
Most common words:
hi: 3
whoa: 2
yay: 2
  • Write a function that omits offensive words. For the purpose of this application, there are only four offensive words to worry about: zoinks, muppeteer, biffaroni, and loopdaloop. These words make the investors behind Text Analzyer fly into a rage. We recommend not using real offensive words because they are, well, offensive! Use TDD to build your function, DRY it up as needed, and then integrate it with your UI.

  • Write a UI function that only bolds the part of the word that matches. For instance, if you are looking for words that match "pen", the boldPassage() method should do this: happen, not this: happen.

Lesson 20 of 34
Last updated October 12, 2021