Skip to content

Instantly share code, notes, and snippets.

@cjsim89
Last active May 9, 2024 14:59
Show Gist options
  • Save cjsim89/50c37f6527aa52e0b302ed7e152b75cb to your computer and use it in GitHub Desktop.
Save cjsim89/50c37f6527aa52e0b302ed7e152b75cb to your computer and use it in GitHub Desktop.
Word Cloud - technical problem

Word Cloud in Ruby

You want to build a word cloud, an infographic where the size of a word corresponds to how often it appears in the body of text. For example, if we turn the Gettysburg Address into a word cloud, it might look like this.

To do this, you'll need data!

Write code that takes a long string and builds its word cloud data into a hash (or JSON object), where the keys are the words and the values are the number of times the words occurred.

Thinking it Through

Think about capitalized words. For example, look at these sentences:

"After beating the eggs, Dana read the next step:"
"Add milk and eggs, then add flour and sugar."

What do we want to do with "After", "Dana", and "add"? In this example, your final hash should include one "Add" or "add" with a value of 2. Make reasonable (not necessarily perfect) decisions about cases like "After" and "Dana".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment