Skip to content

Instantly share code, notes, and snippets.

@hmmhmmhm
Created December 15, 2021 06:34
Show Gist options
  • Select an option

  • Save hmmhmmhm/004f8f356eb395e3e21edea3294a0aa5 to your computer and use it in GitHub Desktop.

Select an option

Save hmmhmmhm/004f8f356eb395e3e21edea3294a0aa5 to your computer and use it in GitHub Desktop.
Modulo in javascript (and typescript).
// ts
const mod = (n: number, m: number) => {
let r = n % m;
return Math.floor(r >= 0 ? r : r + m);
};
// js
const mod = (n, m) => {
let r = n % m;
return Math.floor(r >= 0 ? r : r + m);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment