From 78eb16b295d57a72164a74f336f5240a409772da Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 8 Sep 2021 18:24:37 -0700 Subject: [PATCH] Update data_structures/hash_table/fizz_buzz.rb Co-authored-by: Carlos Augusto M. Filho <41749920+camfilho@users.noreply.github.com> --- data_structures/hash_table/fizz_buzz.rb | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/data_structures/hash_table/fizz_buzz.rb b/data_structures/hash_table/fizz_buzz.rb index f618ad2..92e725e 100644 --- a/data_structures/hash_table/fizz_buzz.rb +++ b/data_structures/hash_table/fizz_buzz.rb @@ -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