dooz.de

Another FizzBuzz version

July 21, 2019

This is my version of the infamous FizzBuzz interview test.

// src/index.js
const range = new Array(100).fill(0);
const f = 'Fizz';
const b = 'Buzz';

function isMod(mod) {
  return number => number % mod === 0;
}

const fizzBuzz = range.map((value, i) => {
  const count = i + 1;

  if (isMod(15)(count)) return f + b;

  if (isMod(3)(count)) return f;

  if (isMod(5)(count)) return b;

  return count;
});

document.getElementById('app').innerHTML = fizzBuzz.join('<br />');
<!-- index.html -->
<!DOCTYPE html>
<html>

<head>
    <title>Another FizzBuzz</title>
    <meta charset="UTF-8" />
</head>

<body>
    <code id="app"></code>
    <script src="src/index.js"><script>
</body>

</html>

Edit on codesandbox.io

What do you think? Tweet me!


Daniel Beutner

Personal blog by Daniel Beutner. Dad, coder and musician.