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
If in-case you don't want your outputs to be consecutive or exact identical and yet want to 'separate an integer into two numbers', this is the solution for you:
function printSeparatedInts(num) {
let smallerNum = Math.floor(Math.random() * Math.floor(num));
if (num && smallerNum === (num/2)) { // checking if input != 0 & output is not consecutive
printSeparatedInts(num)
} else {
console.log(smallerNum, (num - smallerNum))
}
}
printSeparatedInts(22)
printSeparatedInts(22) // will likely print different output from above
printSeparatedInts(7)