数组全排列
程序代码:
<html> <head> <meta charset=utf-8> </head> <body> </body> <script> Array.prototype.全排列=function(){ var r=[]; var that=this; !function(n){ for(var i=n;i<that.length;i++){ [that[i],that[n]]=[that[n],that[i]]; if(n+1<that.length-1) arguments.callee(n+1); else{ r.push(that.slice(0)); }; [that[i],that[n]]=[that[n],that[i]]; } }(0); return r; }; document.body.innerHTML='刘备,张飞,赵云,关羽,黄忠'.split(',').全排列().join('<br>'); </script> </html>