Skip to content

Instantly share code, notes, and snippets.

@John-Lin
Created September 28, 2015 15:10
Show Gist options
  • Select an option

  • Save John-Lin/93f4461aa07972af6178 to your computer and use it in GitHub Desktop.

Select an option

Save John-Lin/93f4461aa07972af6178 to your computer and use it in GitHub Desktop.
For SOA fizzbuzz homework
def fizzbuzz(num, &strategy)
arr = []
1.upto(num) do |i|
if i % 5 == 0 and i % 3 == 0
arr.push("FizzBuzz")
if strategy
yield 'FizzBuzz'
end
elsif i % 3 == 0
arr.push("Fizz")
if strategy
yield 'Fizz'
end
elsif i % 5 == 0
arr.push("Buzz")
if strategy
yield 'Buzz'
end
else
arr.push(i)
if strategy
yield i
end
end
end
arr
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment