Skip to content

Instantly share code, notes, and snippets.

@coolicer coolicer/comb.js
Created Mar 2, 2018

Embed
What would you like to do?
js 排列组合
function C(arr, num)
{
var r=[];
(function f(t,a,n)
{
if (n==0)
{
return r.push(t);
}
for (var i=0,l=a.length; i<=l-n; i++)
{
f(t.concat(a[i]), a.slice(i+1), n-1);
}
})([],arr,num);
return r;
}
function P(arr, num)
{
var r=[];
(function f(t,a,n)
{
if (n==0)
{
return r.push(t);
}
for (var i=0,l=a.length; i<l; i++)
{
f(t.concat(a[i]), a.slice(0,i).concat(a.slice(i+1)), n-1);
}
})([],arr,num);
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.