Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
//全排列就是从第一个数字起每个数分别与它后面非重复出现的数字交换。
var a=[1,2,3];
function swap(array,i,j){
   var temp=array[i];
    array[i]=array[j];
    array[j]=temp;
}
function perman(array,k,end){
   if(k==end){
     console.log(array);
   }
   for(var i=k;i<=end;++i){
      swap(array,k,i);
      perman(array,k+1,end);
      swap(array,k,i);
   }
}
perman(a,0,2)
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers