Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some extensions to Sugar.
Number.extend({
'sign': function() {
// http://stackoverflow.com/a/21294663/3225372
return typeof this === 'number' ? this ? this < 0 ? -1 : 1 : this === this ? this : NaN : NaN;
},
'isPositive': function() {
return this.sign() === 1;
},
'isNegative': function() {
return this.sign() === -1;
},
'isNegativeZero': function() {
// http://www.wirfs-brock.com/allen/posts/128
return this ? false : 1/this === -Infinity;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.