practice-problems-1/comments/20-num-repeats.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.
#
# Difficulty: hard.
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.

hard.
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 . hard .
def num_repeats(string)
  count = 0                                         
  stringHash = Hash.new                             
    string.chars.each do |i|                        
        stringHash[i] = string.count(i)             
    end
    stringHash.each do |k,v|                        
        if v > 1                                    
            count += 1                              
        end
    end
  return count                                      
end
def num_repeats ( string ) count = 0 stringHash = Hash . new string . chars . each do | i | stringHash [ i ] = string . count ( i ) end stringHash . each do | k , v | if v > 1 count += 1 end end return count 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 .
#overall count, will return later # create new hash # loop through each letter in string # create a key in the hash and set the value to the to the number of occurrences of the given key #loop through the hash # if the vale is greater than 1 # add 1 to the overall count # return overall count
string
<not_specific>