Skip to content

Instantly share code, notes, and snippets.

@coolicer
Created March 2, 2018 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coolicer/a30363194a7a4eb73e84229222a3072a to your computer and use it in GitHub Desktop.
Save coolicer/a30363194a7a4eb73e84229222a3072a to your computer and use it in GitHub Desktop.
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