Skip to content

Instantly share code, notes, and snippets.

@clsource
Last active Jul 17, 2020
Embed
What would you like to do?
(() => {
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