Skip to content

Instantly share code, notes, and snippets.

@RobertCam
Created September 29, 2015 20:48
Show Gist options
  • Save RobertCam/0c84826f930ee305054b to your computer and use it in GitHub Desktop.
Save RobertCam/0c84826f930ee305054b to your computer and use it in GitHub Desktop.
FizzBuzz refactored code
def fizzbuzz(start, finish)
start = start.to_i
finish = finish.to_i
range = (start..finish)
for num in range
puts "FIZZBUZZ #{num}" if (num % 3==0)&&(num % 5==0)
puts "FIZZ #{num}" if num % 3==0
puts "BUZZ #{num} " if num % 5==0
puts num if (num % 3!=0)&&(num % 5!=0)
end
end
fizzbuzz("1","10")
fizzbuzz(50, 200)
fizzbuzz(-20, 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment