8. FizzBuzz
EasyLoops~8 min
Return an array of strings for the numbers from 1 to n:
"Fizz"if the number is divisible by 3"Buzz"if it is divisible by 5"FizzBuzz"if it is divisible by both- otherwise the number itself, as a string
Every entry in the returned array is a string, including the plain numbers.
Examples
Example 1
- Input:
- n = 5
- Output:
- ["1", "2", "Fizz", "4", "Buzz"]
Example 2
- Input:
- n = 15
- Output:
- ["1", ..., "FizzBuzz"]
- Why:
- 15 is divisible by both 3 and 5.
Constraints
1 <= n <= 100Every element of the result is a string.