Last active
February 11, 2020 17:52
-
-
Save paulhayes/46489855c7b2ee2afc5de3d1ce8ea24b to your computer and use it in GitHub Desktop.
floored division modulo, where negative dividend behaves like python, i.e seamlessly into the negative range. http://jsben.ch/bU17G
This file contains hidden or 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
| //faster | |
| const mod = (n,d)=>n-d*Math.floor(n/d) |
This file contains hidden or 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
| //slower | |
| const mod = (n,d)=>(d+(n%d))%d; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment