Skip to content

Instantly share code, notes, and snippets.

@parabuzzle
Last active October 20, 2015 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parabuzzle/d30bd33a8fc01f43e67a to your computer and use it in GitHub Desktop.
Save parabuzzle/d30bd33a8fc01f43e67a to your computer and use it in GitHub Desktop.
Needed a simple way of telling me how many of each letter I needed to cut on the laser cutter
def letter_count(str)
str.chars.each_with_object({}) do |char, hash|
next if char == " " # skip spaces
hash.store(char, 0) if hash[char].nil?
hash[char] +=1
end
end
letter_count("hello world").each { |char,count| puts [char, count].join(" == ") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment