Created
January 6, 2015 18:49
-
-
Save jikkujose/7320e89f71fbe2ec0df1 to your computer and use it in GitHub Desktop.
Solution for Raindrops problem in Excercism (https://github.com/exercism/x-common/blob/master/raindrops.md)
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
class RainDrops | |
SOUNDS = { 3 => 'Pling', 5 => 'Plang', 7 => 'Plong' } | |
def make_sound(number) | |
result = SOUNDS.each_with_object([]) do |(factor, sound), record| | |
record << sound if number % factor == 0 | |
end | |
result.empty? ? number : result.join | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment