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