Last active
August 29, 2015 13:57
-
-
Save RoelCastano/9691204 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------- # | |
# Roel Castaño Moreno. # | |
# March 21, 2014. # | |
# Problem 1 for Icalia Labs. # | |
# ----------------------------------------------------- # | |
# Asks for user's input (sentence to be processed). | |
print "Please write a sentence: " | |
sentence = gets.chomp | |
# Downcases the user's input and splits it into an array. | |
arrayWords = sentence.downcase!.split | |
# Creates a hash were the values of the array are stored. | |
# If the word already exists in the hash, the value is incremented by 1. | |
list = Hash.new(0) | |
arrayWords.each do |i| | |
list[i] += 1 | |
end | |
# Outputs each of the words in the hash and its respective count. | |
list.each do |word, count| | |
puts word + " = " + count.to_s | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment