-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathfizzbuzz.js
41 lines (36 loc) · 1.17 KB
/
fizzbuzz.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
Exercise
Write a function that implements the fizzBuzz game.
In fizzBuzz you need to enumerate all the numbers from 1 to `limit`.
If a number is divisible by 3, rather than enumerating the number itself, you need to use 'Fizz'.
If a number is divisible by 5, rather than enumerating the number itself, you need to use 'Buzz'.
If a number is divisible both by 3 and 5, rather than enumerating the number itself, you need to use 'Fizz Buzz'.
Your function receives the `limit` as an argument and needs to return an array with the fizz buzz sequence from 1 to `limit` (included).
For instance if `limit` is `15` you should return:
[
1,
2,
'Fizz', // 3 is divisible by 3
4,
'Buzz', // 5 is divisible by 5
'Fizz', // 6 is dibisible by 3
7,
8,
'Fizz', // 9 is divisible by 3
'Buzz', // 10 is divisible by 5
11,
'Fizz', // 12 is divisible by 3
13,
14,
'Fizz Buzz' // 15 is divisible both by 3 and 5
]
*/
/**
* @param {number} limit
* @returns {[(string|number)]}
*/
export default function fizzBuzz (limit) {
const seq = []
// Write your implementation here. Fill `seq` based on limit
return seq
}