Skip to content

Instantly share code, notes, and snippets.

@marinalaguerre20
Created August 6, 2015 22:24
Show Gist options
  • Save marinalaguerre20/da20e36c6310de115595 to your computer and use it in GitHub Desktop.
Save marinalaguerre20/da20e36c6310de115595 to your computer and use it in GitHub Desktop.
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