Javascript Array combinations()

Description

Javascript Array 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) {/*ww w .j  av a  2  s  .c  o  m*/
    result.push( [array[i],array[j]] );
   }
  }
 }
 return result;
}



PreviousNext

Related