- 1
Modulus
what excactly does the %? i passed the test but dont understand it excactly
3 Answers
+ 6
Same as divide but it is used for the remainder
Like 12%5 will be equal to 2
as the remainder is 2
+ 2
Meta/aside:
Here's a chart including negative value behavior in Javascript:
12 % 7: 5
-12 % 7: -5
12 % -7: 5
-12 % -7: -5
The result takes the sign of the numerator (dividend); other languages use the sign of the denominator (divisor) and the answer will also be correct, but different. This is a policy decision per language.
Not to confuse you (at all), I'm just mentioning this so that you know to check which policy your language uses.
0
It gives you the remainder of an integer division.
a%b=a-a*(floor(a/b))