Skip to content

Instantly share code, notes, and snippets.

@amonmoce
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amonmoce/ebd6d7c17d2017097853 to your computer and use it in GitHub Desktop.
Save amonmoce/ebd6d7c17d2017097853 to your computer and use it in GitHub Desktop.
A fizzbuzz implementation in Ruby language with map ... Rubocop tested "no offense"
def fizzbuzz(n)
numbers = Array.new(n) { |i| i + 1 }
numbers.map! { |x| x % 3 == 0 && x % 5 != 0 ? 'Fizz' : x }
numbers.map! { |x| x % 5 == 0 && x % 3 != 0 ? 'Buzz' : x }
numbers.map! { |x| x % 15 == 0 ? 'FizzBuzz' : x }
print numbers
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment