Last active
October 20, 2015 16:47
Needed a simple way of telling me how many of each letter I needed to cut on the laser cutter
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(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