Last active
March 5, 2018 02:31
-
-
Save etale/9f9218f85a96d4017f45d538530dfe3a to your computer and use it in GitHub Desktop.
Sometimes I want to split an integer.
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
(({ defineProperty }, { prototype }) => ( | |
defineProperty(prototype, 'divmod', { | |
value(a) { | |
return ( | |
a === 0 ? [0, this.valueOf()] : | |
((r) => ( | |
((q) => ( | |
[q, r] | |
))((this - r) / a) | |
))(this % a) | |
) | |
} | |
}), | |
defineProperty(prototype, 'split', { | |
value(a) { | |
return ( | |
this < a ? [ this.valueOf() ] : | |
(([q, r]) => ( | |
q.split(a).concat(r) | |
))(this.divmod(a)) | |
) | |
} | |
}) | |
))(Reflect, Number) |
Author
etale
commented
Mar 1, 2018
Reflect.defineProperty(String.prototype, 'inv', { get() { return this.split('').reverse().join('') } })
String(2**52).inv.match(/(.{1,4})/g).map(a => a.inv).reverse()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment