Modulus Function

function mod(num, mod) { var remain = num % mod; return Math.floor(remain >= 0 ? remain : remain + mod); }
Stumbled upon this in a blog post, for modulus use vs remainder.

1 Response

Very useful !

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.