Skip to content

Instantly share code, notes, and snippets.

@hughfdjackson
Created February 16, 2012 23:56
Show Gist options
  • Select an option

  • Save hughfdjackson/1848933 to your computer and use it in GitHub Desktop.

Select an option

Save hughfdjackson/1848933 to your computer and use it in GitHub Desktop.
fizzbuzz w/ nested ternaries
function fizzbuzz(len){
var res = []
for ( var i = 1; i <= len; i += 1 ) res.push(fizz_or_buzz(i))
return res
function fizz_or_buzz(num){
return num % 3 == 0 && num % 5 == 0 ? "fizzbuzz"
: num % 3 == 0 ? "fizz"
: num % 5 == 0 ? "buzz"
: /* otherwise */ num
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment