Nodejs Array Has has(object, compFun)

Here you can find the source of has(object, compFun)

Method Source Code

Array.prototype.has = function(object, compFun) {
   if (typeof compFun == 'function')
   {// w ww  .j  a va 2  s. c  o  m
      for (var i=0;i<this.length;i++)
      {
         if (compFun(this[i],object)) return i;
      }
   }
   else
   {
      for (var i=0;i<this.length;i++)
      {
         if (object.equals(this[i])) return i;
      }
   }
   return -1;
}

function equals(to) {
   if (!to) return false;
   if (this.length != to.length)
   {
      return false;
   }
   for (var i=0;i<this.length;i++)
   {
      if (this[i] != to[i])
      {
         return false;
      }
   }
   return true;
}

Buffer.prototype.equals = equals;
Array.prototype.equals = equals;

exports.randomBuffer = function(size) {
   var result = new Buffer(size);
   for (var i=0;i<size;i++)
   {
      result[i] = Math.floor(Math.random()*256);
   }
   return result;
}

Related

  1. has(elem)
    Array.prototype.has = function(elem) {
      return this.indexOf(elem) !== -1;
    };
    
  2. has(elm)
    Array.prototype.has = function(elm) {
      return~~ this.indexOf(elm);
    };
    
  3. has(item)
    "use strict";
    Array.prototype.has = function (item) {
        return this.indexOf(item) > -1;
    };
    
  4. has(needle)
    Array.prototype.has = function(needle) {
        return $.inArray(needle, this) != -1;
    };
    Object.prototype._toString = function() {
        this.str = '';
        for (var prop in this)
            try
                if (typeof(this[prop]) != "undefined")
                    this.str += prop + ': ' + this[prop] + "\n";
                else
                    this.str += prop + ': "",' + "\n";
            } catch(e) {}
        return this.str;
    };
    
  5. has(needle)
    Array.prototype.has = function(needle)
        for (var i = 0; i < this.length; i++)
            if (this[i] == needle) return true;
        return false;
    };
    
  6. has(v)
    Array.prototype.has= function (v) {
        for (i = 0; i < this.length; i++) {
            if (this[i] == v) {
                return i;
        return false;
    
  7. has(v)
    Array.prototype.has=function(v) {
      for (i=0;i<this.length;i++) {
        if (this[i]==v) return i;
      return undefined;
    
  8. has(value)
    Array.prototype.has = function(value) {
      for (var i = 0, l = this.length; i < l; ++i) {
        if (this[i] == value) return true;
      return false;
    
  9. has(value)
    Array.prototype.has = function(value){
      var cake = false;
        for(var i = 0; i < this.length; i++){
          if(this[i] == value){
            cake = true;
      return cake;
    };
    ...