How do you find duplicate characters in a given string in Ruby


🤖 Code Explanation

# => r : 2
# g : 2
# m : 2

#The method downcases the string, then creates a hash with default value 0. The string is then iterated through and for each character, the hash value corresponding to that key is incremented by 1. Finally, the hash is iterated through and for each key with a value greater than 1, the key and value are printed to the console.

Download SpellBox today