Skip to content

Instantly share code, notes, and snippets.

@gartenfeld
Last active August 29, 2015 14:22
Show Gist options
  • Save gartenfeld/eafef2997f18081b1fe3 to your computer and use it in GitHub Desktop.
Save gartenfeld/eafef2997f18081b1fe3 to your computer and use it in GitHub Desktop.
A less readable rendition of FizzBuzz.
var f = function (n) {
var s = "";
// 0 is falsy, the ternary then evaluates to the value right of the colon
s += n % 3 ? "" : "Fizz";
s += n % 5 ? "" : "Buzz";
// empty string is also falsy
return s ? s : n;
};
console.log(f(7));
console.log(f(12));
console.log(f(20));
console.log(f(30));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment