Created
April 21, 2017 03:47
-
-
Save AakashL/bf26d93c904f9aa45f3f662b71463274 to your computer and use it in GitHub Desktop.
Fizz Buzz
This file contains 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 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