Nodejs Array Contain contains(index, obj)

Here you can find the source of contains(index, obj)

Method Source Code

/**//from   w w  w  .  java 2  s.  c om
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function(nums, target) {
   for (var i = nums.length - 1; i >= 0; i--) {
      let val = target - nums[i];
      if (nums.contains(i, val) === true) {
         return [nums.indexOf(val), i];
      }
   }
   return [];
};

Array.prototype.contains = function(index, obj) {
   var i = this.length;
   while (i--) {
      if (i != index && this[i] === obj) {
         return true;
      }
   }
   return false;
};

console.log(twoSum([3,2,4], 6));

Related

  1. contains(element)
    Array.prototype.contains = function(element) {
        return (arrValues.indexOf(element) > -1);
    
  2. contains(element)
    Array.prototype.contains = function(element) {
      if(!element)
        return false;
      for (var e in this) {
        var arrayElement = this[e];
        if(element == arrayElement) {
          return true;
    ...
    
  3. contains(element)
    Array.prototype.contains = function(element){ 
        return this.indexOf(element) > -1;
    };
    
  4. contains(elm)
    Array.prototype.contains = function(elm) {
      for (var i = 0; i < this.length; i++) {
        if (elm == this[i]) return true;
      return false;
    };
    
  5. contains(i)
    Array.prototype.contains = function(i) {
        return this.indexOf(i) > -1;
    };
    
  6. contains(item)
    Array.prototype.contains = function (item) {
        return this.indexOf(item) != -1
    
  7. contains(item)
    Array.prototype.contains = function(item) {
      return this.indexOf(item) !== -1;
    };
    
  8. contains(item)
    Array.prototype.contains = function(item){
        return RegExp("(^|,)" + item.toString() + "($|,)").test(this);
    };
    
  9. contains(item)
    Array.prototype.contains = function (item) {
      return RegExp("\\b"+item+"\\b").test(this);
    };