Does anybody see below javascript recursive with shift() return? Even three times shift() array still run 'while loop'
function combine(nums) {
while (nums.length) {
let r = nums.shift();
console.log(r, ':', nums);
combine(nums.slice(0));
}
}
combine([1,2,3])
--------------- return -----------
1 : [ 2, 3 ]
2 : [ 3 ]
3 : []
3 : []
2 : [ 3 ]
3 : []
3 : []
------------------------------------
returnwill avoidwhileto continue the next iteration.