Skip to main content
deleted 3 characters in body
Source Link
steenslag
  • 522
  • 2
  • 8

No nested if's (and no ternary operators):

def fizzbuzz(n) (1..100).each do |n| res = "" res << "Fizz" if n % 5 == 0 res << "Buzz" if n % 3 == 0 res << n.to_s if res.empty? puts res end end 

With one extra line of code this transforms to a FizzBuzzBazz.

No nested if's (and no ternary operators):

def fizzbuzz(n) (1..100).each do |n| res = "" res << "Fizz" if n % 5 == 0 res << "Buzz" if n % 3 == 0 res << n.to_s if res.empty? puts res end end 

With one extra line of code this transforms to a FizzBuzzBazz.

No nested if's (and no ternary operators):

def fizzbuzz (1..100).each do |n| res = "" res << "Fizz" if n % 5 == 0 res << "Buzz" if n % 3 == 0 res << n.to_s if res.empty? puts res end end 

With one extra line of code this transforms to a FizzBuzzBazz.

Source Link
steenslag
  • 522
  • 2
  • 8

No nested if's (and no ternary operators):

def fizzbuzz(n) (1..100).each do |n| res = "" res << "Fizz" if n % 5 == 0 res << "Buzz" if n % 3 == 0 res << n.to_s if res.empty? puts res end end 

With one extra line of code this transforms to a FizzBuzzBazz.