Skip to content

Commit f514b33

Browse files
author
Tymoteusz
authored
Merge pull request #2 from 403-html/fizzbuzz
Fizzbuzz
2 parents 5e995a8 + 7a16599 commit f514b33

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

fizzbuzz/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# FizzBuzz array
2+
3+
FizzBuzz is the "Hello World" of technical interview questions. Your function should write the numbers from 1 to n with a twist; instead of any multiplier of 3, you output Fizz, instead of multiplers of 5 you output Buzz, and if they happen at the same time, you should use FizzBuzz. The output of your function should be a mixed array of numbers and strings.
4+
5+
> Description found in [javascript.onl](https://javascript.onl/problems/1.html)

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)