Skip to content

Instantly share code, notes, and snippets.

@paulhayes
Last active February 11, 2020 17:52
Show Gist options
  • Select an option

  • Save paulhayes/46489855c7b2ee2afc5de3d1ce8ea24b to your computer and use it in GitHub Desktop.

Select an option

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
//faster
const mod = (n,d)=>n-d*Math.floor(n/d)
//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