Skip to content

Instantly share code, notes, and snippets.

@MaxXxiMast
Last active June 25, 2019 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaxXxiMast/5d6c3d70ed726b9c7e9c680ab8373a34 to your computer and use it in GitHub Desktop.
Save MaxXxiMast/5d6c3d70ed726b9c7e9c680ab8373a34 to your computer and use it in GitHub Desktop.
Check the Sign on a Number taking -ve 0 into consideration
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