We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5e995a8 commit 4519e24Copy full SHA for 4519e24
1 file changed
fizzbuzz/fizzbuzz.js
@@ -0,0 +1,18 @@
1
+const isDividiedBy = (num, multiplier) => {
2
+ if (num % multiplier == 0) {
3
+ return true
4
+ }
5
+}
6
+const fizzbuzz = (n) => {
7
+ return new Array(n).fill('').map((val, index) => {
8
+ if (isDividiedBy(index + 1, 3) && isDividiedBy(index + 1, 5)) {
9
+ return 'FizzBuzz'
10
+ } else if (isDividiedBy(index + 1, 3) || isDividiedBy(index + 1, 5)) {
11
+ if (isDividiedBy(index + 1, 3)) return 'Fizz'
12
+ if (isDividiedBy(index + 1, 5)) return 'Buzz'
13
14
+ return index + 1
15
+ })
16
17
+
18
+console.log(fizzbuzz(15))
0 commit comments