Here you can find the source of combinations()
Array.prototype.combinations = function() { var array = this; var result = []; for(var i = 0; i < array.length; i++) { for (var j = i+1; j < array.length; j++) { if (i != j) { result.push( [array[i],array[j]] ); }//from w w w .j a v a2 s . c om } } return result; }
Array.prototype.combinationsOf = function(k) { var result = []; if (k < 1) return result; if (k > this.length) return result; if (k == this.length) return this.slice(0); var indices = new Array(k), n = this.length; var total = n.factorial() / ((n - k).factorial() * k.factorial()); indices.length.times(function(i) { indices[i] = i }); result.push(this.valuesAt(indices)); ...