Skip to content

A hash list of words and their number of occurrences from a given string.

Notifications You must be signed in to change notification settings

grenzk/substrings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sub Strings

Implement a method #substrings that takes a word as the first argument and then an array of valid substrings (your dictionary) as the second argument. It should return a hash listing each substring (case insensitive) that was found in the original string and how many times it was found.

> dictionary = %w[below, down, go, going, horn, how, howdy, it, i, low, own, part, partner, sit]

=> ["below","down","go","going","horn","how","howdy","it","i","low","own","part","partner","sit"]

> substrings("below", dictionary)

=> { "below" => 1, "low" => 1 }

A method that can handle multiple words:

> substrings("Howdy partner, sit down! How's it going?", dictionary)

=> { "down" => 1, "go" => 1, "going" => 1, "how" => 2, "howdy" => 1, "it" => 2, "i" => 3, "own" => 1, "part" => 1, "partner" => 1, "sit" => 1 }

Source

The Odin Project (https://www.theodinproject.com/paths/full-stack-ruby-on-rails/courses/ruby-programming/lessons/sub-strings)

About

A hash list of words and their number of occurrences from a given string.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages