Here you can find the source of permute(len)
Array.prototype.permute = function(len) { var ret = []; for (var i = 0; i < this.length; i++) { var c = this[i]; if (len > 1) { var sub = this.permute(len - 1); for (var j = 0; j < sub.length; j++) { ret.push(c + sub[j]);//from www . j av a 2s . c o m } } else return this; } return ret; };
Array.prototype.permutations = function(n){ var perms = [], array = this; var compute_perms = function(n){ if(n==1) perms.push(array.join('')); else{ for(var i=0; i!=n; i++){ compute_perms(n-1); ...
"use strict"; Array.prototype.permutations = function Array_permutations() { if (this.length === 1) { return [this]; var permutations = [], tmp, fixed; for (var i=0; i<this.length; i++) { tmp = this.slice(); ...