Skip to content

Instantly share code, notes, and snippets.

@jordanhudgens
Created September 19, 2018 22:52
Show Gist options
  • Save jordanhudgens/3f0fb6578caa794226a472f3a125a787 to your computer and use it in GitHub Desktop.
Save jordanhudgens/3f0fb6578caa794226a472f3a125a787 to your computer and use it in GitHub Desktop.
const functionalFizzBuzz = n => {
return Array.from(
{ length: n },
(_, idx) =>
[[15, "fizzbuzz"], [5, "buzz"], [3, "fizz"]].find(
val => (idx + 1) % val[0] === 0
) || idx + 1
).reduce((acc, el) => (acc += (el[1] || el) + "\n"), "");
};
functionalFizzBuzz(15);
// "1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizzbuzz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment