Skip to content

Instantly share code, notes, and snippets.

@mendelB
Created July 29, 2015 15:58
Show Gist options
  • Save mendelB/8f35ef58cf5d3bd80907 to your computer and use it in GitHub Desktop.
Save mendelB/8f35ef58cf5d3bd80907 to your computer and use it in GitHub Desktop.
sentence = <<-something
Steven likes the movies. Blake likes to ride his bike but hates movies.
Blake is taller than steven. Steven is a great teacher.
something
sentence2 = sentence.gsub('.', '').split(' ')
sentence2 = sentence2.collect { |i| i = i.upcase }
num = 1
word = nil
count = 0
counter = 0
most_word = nil
sentence2.each do |i|
count = 0
word = i
count += 1
while num < sentence2.length
if sentence2[num] == word
count += 1
end
num += 1
end
if count > counter
counter = count
most_word = word
end
end
most_word
counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment