Skip to content

Instantly share code, notes, and snippets.

@KoljaL
Created June 6, 2023 07:16
Show Gist options
  • Save KoljaL/bbb8b4cfb55df686757c91e3f13101c9 to your computer and use it in GitHub Desktop.
Save KoljaL/bbb8b4cfb55df686757c91e3f13101c9 to your computer and use it in GitHub Desktop.
Collected functions for util.js
// return *positive* remainder of n divided by m.
export function mod(n, m) {
return ((n % m) + m) % m;
}
export function sleep(time) {
return new Promise((res) => setTimeout(res, time));
}
function randInt(a, b) {
return a + Math.floor((b - a) * Math.random());
}
export function randEl(list) {
return list[randInt(0, list.length)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment