Created
October 26, 2015 16:37
-
-
Save martinlaws/1e98e7677b12744d3686 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def letter_count(string) | |
| counting = Hash.new(0) | |
| indexing = Hash.new { |hash, key| hash[key] = [] } | |
| string.split('').each_with_index do |letter, index| | |
| next if letter == ' ' | |
| counting[letter] += 1 | |
| indexing[letter] << index | |
| end | |
| puts counting | |
| puts indexing | |
| end | |
| letter_count('hello, my name is martin!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment