Last active
June 25, 2019 06:45
-
-
Save MaxXxiMast/5d6c3d70ed726b9c7e9c680ab8373a34 to your computer and use it in GitHub Desktop.
Check the Sign on a Number taking -ve 0 into consideration
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
function checkSign(x){ | |
return x !== 0 ? Math.sign(x) : Object.is(x, -0) ? -1 : 1; | |
} | |
checkSign(-0) // -1 i.e. -ve sign | |
checkSign(0) // 1 i.e. +ve sign | |
checkSign(-6) // -1 | |
checkSign(6) // 1 | |
credits: Kyle Simpson (getify) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment