I need to generate different combinations of numbers based on the input provided. For example, if the input is 3, there would be 8 combinations as shown below:
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
For input 4, there would be 16 combinations. Currently, I am achieving this using nested for loops in JavaScript like so:
value1 = 2, value2 = 2, value3 = 2;
my function () {
for(var i = 0; i<this.value1; i++) {
for(var j = 0; j < this.value2; j++) {
for(var k = 0; k < this.value3; k++) {
console.log(i,j,k);
}
}
}
}
However, this approach works well for small inputs but becomes impractical for larger ones like 10. I believe recursion could be a better solution, but I'm not sure how to implement it in this scenario. Any assistance or guidance would be greatly appreciated.