simple-exercises/ruby-exercises/easy-2.rb
# Write a method that takes in a string and returns the number of
# letters that appear more than once in the string. You may assume
# the string contains only lowercase letters. Count the number of
# letters that repeat, not the number of times they repeat in the
# string.
Write a method that takes in a string and returns the number of
letters that appear more than once in the string. You may assume
the string contains only lowercase letters. Count the number of
letters that repeat, not the number of times they repeat in the
string.
Write a method that takes in a string and returns the number of letters that appear more than once in the string . You may assume the string contains only lowercase letters . Count the number of letters that repeat not the number of times they repeat in the string .
def num_repeats(string)
  n = 0
  repeats = Hash.new(0)
  string.each_char do |c|
    repeats[c] += 1
    if repeats[c] == 2
      n += 1
    end
  end
  n
end
def num_repeats ( string ) n = 0 repeats = Hash . new ( 0 ) string . each_char do | c | repeats [ c ] += 1 if repeats [ c ] == 2 n += 1 end end n end
Write a method that takes in a string and returns the number of
letters that appear more than once in the string.
Write a method that takes in a string and returns the number of letters that appear more than once in the string .
# number of repeating characters # tracks the character frequency
string
<not_specific>