Javascript Array zeroPairs()

Description

Javascript Array zeroPairs()

Array.prototype.zeroPairs = function() {
  var pairs = [];

  for (var i = 0; i < this.length - 1; i++) {
    for (var j = i + 1; j < this.length; j++) {
      if (this[i] + this[j] === 0) {
        pairs.push([i, j]);//from  w ww  .jav a2  s  .  c o m
      }
    }
  }

  return pairs;
};



PreviousNext

Related