I need to separate an integer into two numbers. Something like dividing by two but I only want integer components as a result, such as:
6 = 3 and 3 7 = 4 and
Just find the first part and subtract it from the original number.
var x = 7; var p1 = Math.floor(x / 2); var p2 = x - p1; console.log(p1, p2);
In the case of x being odd, p1 will receive the smaller of the two addends. You can switch this around by calling Math.ceil instead.
x
p1
Math.ceil