FizzBuzz
FizzBuzz, and other similar test scenarios, is the bane of many a developer looking for a new role. When looking for that new role you may be confronted by this puzzle as part of a 'Code Test' often used in the recruiting process.
We're not necessarily saying that code tests are a waste of time, but we are not sure they are the best way to discover new talent.
'Fizz buzz'
is a simple children game which is often used as a code test challenge. The idea is simple, you are given a number and if the number is divisible by 3 you would return 'Fizz', if it is divisible by 5 you would return 'Buzz' and if it is divisible by both by 3 and 5 you would return 'FizzBuzz'. Otherwise you would return the original number.
It essentially tests whether the programmer (or child) can solve the problem efficiently and the method they might use, i.e. do you check if it divides by 3 and 5, or do you go for the shortcut and see if it divides by 15?
Depending on the given task, sometimes the solution requires a function that returns a single answer to a single input (e.g. 3 is sent to the function and it returns 'Fizz'), other times the solution will return (or display in the console) an answer to each number in a range (e.g. 1,2,3,4,5,6, etc. => '1', '2', 'Fizz', '4', 'Buzz', '6', etc.)
Well, we have put a little slant on this puzzle. Hope you like our answer?
We run each of these functions consecutively in individual
WebWorkers
with values in the range from 1 to 100,000,000. The resulting times shown under each code example.
Now click the run button:
fizzbuzzCalculator1
let result;
if (value % 15 === 0) {
result = "FizzBuzz";
} else if (value % 3 === 0) {
result = "Fizz";
} else if (value % 5 === 0) {
result = "Buzz";
} else {
result = value.toString();
}
Time:
fizzbuzzCalculator2
let result;
if (value % 3 === 0 && value % 5 === 0) {
result = "FizzBuzz";
} else if (value % 3 === 0) {
result = "Fizz";
} else if (value % 5 === 0) {
result = "Buzz";
} else {
result = value.toString();
}
Time:
fizzbuzzCalculator3
let result = "";
if (value % 3 === 0) {
result = "Fizz";
}
if (value % 5 === 0) {
result += "Buzz";
}
if (result === "") {
result = value.toString();
}
Time:

FUTORO