Skip to content

Instantly share code, notes, and snippets.

@metanomial
Created December 13, 2019 22:12
Show Gist options
  • Save metanomial/18695b95517d0b78bb882ffe78ce16dd to your computer and use it in GitHub Desktop.
Save metanomial/18695b95517d0b78bb882ffe78ce16dd to your computer and use it in GitHub Desktop.
BigInt.prototype.abs
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