Skip to content

Commit 4519e24

Browse files
committed
Add fizzbuzz function
1 parent 5e995a8 commit 4519e24

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

fizzbuzz/fizzbuzz.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)