Skip to content

Instantly share code, notes, and snippets.

@sharpred
Last active September 14, 2017 13:33
Show Gist options
  • Save sharpred/1217327d09c52166019b3dbf227fc313 to your computer and use it in GitHub Desktop.
Save sharpred/1217327d09c52166019b3dbf227fc313 to your computer and use it in GitHub Desktop.
calc fizzbuzz
const fizzBuzz = x => {
let test1 = x % 3 === 0 ? 1 : 0;
let test2 = x % 5 === 0 ? 2 : 0;
return test1 | test2;
};
const printFizzBuzz = (item, val) => {
let x = val + 1;
switch (fizzBuzz(x)) {
case 1:
console.log("Fizz");
break;
case 2:
console.log("Buzz");
break;
case 3:
console.log("FizzBuzz");
break;
default:
console.log(x);
break;
}
}
Array(100).fill("").forEach(printFizzBuzz);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment