Skip to content

Instantly share code, notes, and snippets.

@AakashL
Created April 21, 2017 03:47
Show Gist options
  • Save AakashL/bf26d93c904f9aa45f3f662b71463274 to your computer and use it in GitHub Desktop.
Save AakashL/bf26d93c904f9aa45f3f662b71463274 to your computer and use it in GitHub Desktop.
Fizz Buzz
class FizzBuzz
def initialize(endpoint)
@endpoint = endpoint
end
def play
return '' unless @endpoint.is_a? Integer
return '' if @endpoint <= 0
result = []
for number in 1..@endpoint
result << at(number)
end
return result.join(',')
end
def at(target)
return "" if target > @endpoint
if (target%3==0 and target%5 ==0)
then 'fizzbuzz'
elsif target %3==0 then 'fizz'
elsif target %5==0 then 'buzz'
else target
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment