Created
April 29, 2016 14:59
-
-
Save joshuastr/10e5ec311d2837da8c428cabe39803cf to your computer and use it in GitHub Desktop.
This file contains 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 count_letters(str) | |
data = {} | |
str.split('').each do |l| | |
puts l | |
next if l == ' ' | |
if data[l].nil? | |
data[l] = 1 | |
else | |
data[l] += 1 | |
end | |
end | |
p data | |
end | |
#count_letters("counting these letters") | |
def letter_count_index(str) | |
data = Hash.new {|h,k| h[k]=[]} | |
str.split('').each_with_index do |item, index| | |
data[item] << index | |
end | |
p data | |
end | |
letter_count_index("counting these letters") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment