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.