Skip to content

Instantly share code, notes, and snippets.

@jikkujose
Created January 6, 2015 18:49
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 jikkujose/7320e89f71fbe2ec0df1 to your computer and use it in GitHub Desktop.
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)
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