Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert boolean to positive (1) negative (-1)
const condition = true;
// I don't know why, but adding an if here makes me sad since I started programming :L
condition ? 1 : -1;
// Alternative way 1
(-1) ** condition;
// Alternative way 2
2 * condition - 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment