Declarative FizzBuzz
Dylan Slack
81

Even better is to refactor 1 more time:

const isDivisibleBy = (num, divisor) => num % divisor === 0;
const calculateState = (index) => {
let by3 = isDivisibleBy(index, 3),
by5 = isDivisibleBy(index, 5),
byBoth = by3 && by5;

return byBoth ? 'FizzBuzz' :
by3 ? 'Fizz' :
by5 ? 'Buzz' : index;
}

const fizzDatBuzz = (value, idx) => {
console.log( calculateState(++idx));
};
Array(100).fill().forEach(fizzDatBuzz);
Like what you read? Give Thomas Burleson a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.