Skip to content

Instantly share code, notes, and snippets.

@clsource
Last active July 17, 2020 01:17
Show Gist options
  • Select an option

  • Save clsource/5e03f493f96223717a357c7c040407b0 to your computer and use it in GitHub Desktop.

Select an option

Save clsource/5e03f493f96223717a357c7c040407b0 to your computer and use it in GitHub Desktop.
(() => {
const numbers = [0, 3, 5, 10, 15, 20, 25, 30];
const FIZZ = 3;
const FIZZ_WORD = "Fizz";
const BUZZ = 5;
const BUZZ_WORD = "Buzz";
const checkModuleIsZero = (numerator, denominator) => {
return numerator % denominator === 0;
};
const checkStateFizz = (num) => {
return checkModuleIsZero(num, FIZZ);
};
const checkStateBuzz = (num) => {
return checkModuleIsZero(num, BUZZ);
};
let state;
numbers.forEach(number => {
state = null;
if(checkStateFizz(number)) {
state = FIZZ_WORD;
if(checkStateBuzz(number)) {
state += BUZZ_WORD;
}
}
if(!state && checkStateBuzz(number)) {
state = BUZZ_WORD;
}
console.log({number, state});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment