mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-25 21:58:57 +01:00
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:
parent
d73d64ed95
commit
78eb16b295
1 changed files with 3 additions and 12 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue