simple-exercises/ruby-exercises/easy-3.rb
# Word With Most Repeats
# ------------------------------------------------------------------------------
# Given a sentence, find which word has the greatest amount of repeated letters.
#
# For example, "I took the road less traveled and that has made all the difference"
# should return "difference" because it has two repeated letters (f and e).
#
# All words will be separated by spaces and there will be no punctuation or
# capitalization.  If there is a tie return the first word.  It doesn't matter
# how many times individual letters repeat, just that they repeat (see the third test
# case).
Word With Most Repeats
Given a sentence, find which word has the greatest amount of repeated letters.

For example, "I took the road less traveled and that has made all the difference"
should return "difference" because it has two repeated letters (f and e).

All words will be separated by spaces and there will be no punctuation or
capitalization.  If there is a tie return the first word.  It doesn't matter
how many times individual letters repeat, just that they repeat (see the third test
case).
Word With Most Repeats Given a sentence find which word has the greatest amount of repeated letters . For example " I took the road less traveled and that has made all the difference " should return " difference " because it has two repeated letters ( f and e ) . All words will be separated by spaces and there will be no punctuation or capitalization . If there is a tie return the first word . It doesn ' t matter how many times individual letters repeat just that they repeat ( see the third test case ) .
def count_repeated_letters(word)
  occurences = Hash.new(0)
  count = 0
  word.each_char do |c|
    occurences[c] += 1
    if occurences[c] == 2
      count+=1
    end
  end
  count
end
def count_repeated_letters ( word ) occurences = Hash . new ( 0 ) count = 0 word . each_char do | c | occurences [ c ] += 1 if occurences [ c ] == 2 count += 1 end end count end
Word With Most Repeats
Given a sentence, find which word has the greatest amount of repeated letters.
Word With Most Repeats Given a sentence find which word has the greatest amount of repeated letters .
# character: # of occurences
word
<not_specific>