modulo of the positive number
// num % m
num % m;
π₯ modulo of a negative number
To achieve the same result in Javascript, you can use a workaround by
- adding the divisor to the dividend
- computing the modulo operation.
This will ensure that the dividend is positive and the modulo operation returns a positive result.
// num % m
((num % m) + m) % m;
π₯ algorithm
const mod = (num % m) => {
return ((num % m) + m) % m;
}