Modo entrevista. Cronômetro de 10 min, sem dicas e sem autocompletar
FizzBuzz
FácilBasics10 min
Write a function fizzBuzz(n) that returns an array of strings for the numbers from 1 to n, in order. Each number gives one element of the array:
'FizzBuzz'if the number divides by 3 and by 5 with no remainder (15, 30, 45, ...);'Fizz'if it divides by 3 but not by 5 (3, 6, 9, ...);'Buzz'if it divides by 5 but not by 3 (5, 10, 20, ...);- otherwise the number itself as a string:
'7', not the number7.
n is an integer, 0 or more. Both 1 and n are included. If n is 0, return an empty array [].
Exemplos
fizzBuzz(5)Retorna [ '1', '2', 'Fizz', '4', 'Buzz' ]
fizzBuzz(15)Retorna [ '1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz' ]
fizzBuzz(0)Retorna []
Carregando o editor...
- Entrada
fizzBuzz(5)Esperado[ '1', '2', 'Fizz', '4', 'Buzz' ] - Entrada
fizzBuzz(15)Esperado[ '1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz' ] - Entrada
fizzBuzz(0)Esperado[]
Os testes ocultos rodam no envio