Skip to content

Instantly share code, notes, and snippets.

@martinlaws
Created October 26, 2015 16:37
Show Gist options
  • Select an option

  • Save martinlaws/1e98e7677b12744d3686 to your computer and use it in GitHub Desktop.

Select an option

Save martinlaws/1e98e7677b12744d3686 to your computer and use it in GitHub Desktop.
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