Skip to content

Instantly share code, notes, and snippets.

@silasolla
Last active September 21, 2023 23:35
Show Gist options
  • Save silasolla/d765cfe37225a0f3c74eb3a8266d72d8 to your computer and use it in GitHub Desktop.
Save silasolla/d765cfe37225a0f3c74eb3a8266d72d8 to your computer and use it in GitHub Desktop.
One-liner flip-flop implementation written in JavaScript
flip = flop = () => (flip = () => (flip = flop) | 0) | 1
@silasolla
Copy link
Author

silasolla commented Sep 21, 2023

inspired by kazuho/fizzbuzz.js.

$ node
Welcome to Node.js v20.7.0.
Type ".help" for more information.
> flip = flop = () => (flip = () => (flip = flop) | 0) | 1
[Function: flop]
> flip()
1
> flip()
0
> flip()
1
> flip()
0
> flip()
1
>

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