Nodejs Utililty Methods Array Combination

List of utility methods to do Array Combination

Description

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

Method

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]] );
  return result;
combinationsOf(k)
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));
...