Skip to content

Instantly share code, notes, and snippets.

@goshki
Last active December 16, 2021 20:38
Show Gist options
  • Save goshki/484945 to your computer and use it in GitHub Desktop.
Save goshki/484945 to your computer and use it in GitHub Desktop.
// Prints to browser console (Chrome, Firefox), no explicit ifs. Starts from 1.
for(i=0;i++<100;console.log([['fizz'][i%3],['buzz'][i%5]].join('')||i)); // 72 characters
// Writes to array 'a', no explicit ifs. Starts from 1.
for(a,i=0;i<100;a[i++]=([['fizz'][i%3],['buzz'][i%5]].join('')||i)); // 68 characters
// Returns an array (Firefox only), no explicit ifs, no explicit loops. Starts from 0.
Array.apply([],Array(100)).map((e,i)=>[['fizz'][i%3],['buzz'][i%5]].join('')||i) // 80 characters
function fizzbuzz( i ) {
return [ [ 'fizz' ][i%3], [ 'buzz' ][i%5] ].join( '' ) || i;
}
@dmoath
Copy link

dmoath commented Oct 17, 2020

for(i=0;i<100;console.log((++i%3?'':'fizz')+(i%5?'':'buzz')||i)); //66 characters :)

@goshki
Copy link
Author

goshki commented Oct 23, 2020

👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment