Created
December 13, 2019 22:12
-
-
Save metanomial/18695b95517d0b78bb882ffe78ce16dd to your computer and use it in GitHub Desktop.
BigInt.prototype.abs
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
Object.defineProperty(BigInt.prototype, 'abs', { | |
get() { | |
return this.valueOf() < 0n | |
? this.valueOf() * -1n | |
: this.valueOf(); | |
} | |
}) | |
(15n).abs; // 15n | |
(-5n).abs; // 5n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment