Created
August 6, 2015 22:24
-
-
Save marinalaguerre20/da20e36c6310de115595 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
puts "please enter some text" | |
class Frequency_count | |
def count_words | |
@text = gets.chomp | |
@words = @text.split(' ') | |
@frequency = Hash.new(0) | |
@words.each { |word| @frequency[word.downcase] += 1 } | |
return @frequency | |
end | |
def max_value | |
max = @frequency.sort {|b, a| a[1]<=> b[1]} | |
return max[0][0] | |
end | |
end | |
fc = Frequency_count.new | |
puts fc.count_words | |
puts fc.max_value + " " + "is the word used most" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment