1var y=11;
2var x=4;
3var quotient = Math.floor(y/x); //2
4var remainder = y % x; //3
1 var myNum = 10 / 4; // 2.5
2 var fraction = myNum % 1; // 0.5
3 myNum = -20 / 7; // -2.857142857142857
4 fraction = myNum % 1; // -0.857142857142857
5
1function mod(n, a, b) {
2 n = n | 0;
3 a = a | 0;
4 b = b | 0;
5 let rem;
6 if (a < 0 || b < 0) {
7 const places = (b - a);
8 rem = (n - a) % (places + 1);
9 rem = rem < 0 ? (rem + (places + 1)) : rem === 0 ? 0 : rem;
10 return rem - (places - b);
11 }
12 if (n === b) return n;
13 if (n === b + 1) return a;
14 if (n === a - 1) return b;
15 rem = n % (b || 1);
16 rem = rem < a ? (rem + b) : rem === 0 ? 0 : rem;
17 return rem;
18}
19
20mod(1, 1, 5); // 1
21mod(0, 1, 5); // 5
22mod(0, -1, 5); // 0
23mod(-2, -1, 5); // 5