Created
October 29, 2020 10:39
-
-
Save jonasraoni/a7bd7c5ca328543d88afa94e9ef2d184 to your computer and use it in GitHub Desktop.
Convert boolean to positive (1) negative (-1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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