New answers tagged

2

There is a trick to achieve this. Basically you always keep the subset you are currently considering sorted. subset = []; function forSubsets(n,k,m=1){ if(subset.length == k) console.log(subset); else{ for(var i = m; i <= n; i++){ subset.push(i); forSubsets(n,k,i); subset.pop(); } } } As you can see on each recursion one ...


Top 50 recent answers are included