Mode entretien. Minuteur de 10 min, sans indices ni autocomplétion
FizzBuzz
FacileBasics10 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 [].
Exemples
fizzBuzz(5)Renvoie [ '1', '2', 'Fizz', '4', 'Buzz' ]
fizzBuzz(15)Renvoie [ '1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz' ]
fizzBuzz(0)Renvoie []
Chargement de l'éditeur...
- Entrée
fizzBuzz(5)Attendu[ '1', '2', 'Fizz', '4', 'Buzz' ] - Entrée
fizzBuzz(15)Attendu[ '1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz' ] - Entrée
fizzBuzz(0)Attendu[]
Les tests cachés se lancent à la soumission