Nodejs Utililty Methods Array Permutation

List of utility methods to do Array Permutation

Description

The list of methods to do Array Permutation are organized into topic(s).

Method

permutations(n)
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);
...
permutationsArray_permutations()
"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();
...
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]);
        } else return this;
    return ret;
};