Update data_structures/hash_table/fizz_buzz.rb

Co-authored-by: Carlos Augusto M. Filho <41749920+camfilho@users.noreply.github.com>
This commit is contained in:
Vitor Oliveira 2021-09-08 18:24:37 -07:00 committed by GitHub
parent d73d64ed95
commit 78eb16b295
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,13 +15,8 @@
# @param {Integer} n
# @return {String[]}
def fizz_buzz(n)
str = []
fizz_buzz = {}
fizz_buzz[3] = 'Fizz'
fizz_buzz[5] = 'Buzz'
n.times do |i|
def fizz_buzz(n, fizz_buzz = { 3 => 'Fizz', 5 => 'Buzz' })
n.times.map do |i|
i += 1
num_str = ''
@ -29,12 +24,8 @@ def fizz_buzz(n)
num_str += value if i % key == 0
end
num_str = i.to_s if num_str == ''
str.push(num_str)
num_str.empty? ? i.to_s : num_str
end
str
end
n = 15