Javascript Array twoSum(sum)

Description

Javascript Array twoSum(sum)

Array.prototype.twoSum = function (sum) {
  var indices = [];
  for (var i = 0; i < this.length; i++) {
    for ( j = i + 1; j < this.length; j++) {
      if (this[i] + this[j] === sum) { indices.push([i,j]); }
    }/*  ww  w.  jav  a 2  s. c om*/
  }
  return indices;
}



PreviousNext

Related