Nodejs Array Push Unique pushUniq(el, test)

Here you can find the source of pushUniq(el, test)

Method Source Code

Array.prototype.pushUniq = function(el, test) {
    if (test == null) {
        if (this.indexOf(el) < 0) {
            this.push(el);//from  w  w  w.  j a  v a 2 s .c o  m
            return true;
        }
        return false;
    }
    for (var i = this.length; --i >= 0;)
        if (test(this[i], el)) return false;
    this.push(el);
    return true;
};

Related

  1. pushIfUnique(entryIn)
    Array.prototype.pushIfUnique = function(entryIn){
        var arr = this;
        var unique = true;
        arr.forEach(function(entry){
            if(entryIn === entry){
                unique = false;
        });
        if(unique){
    ...
    
  2. pushUnique(item)
    Array.prototype.pushUnique = function(item){
        if(this.indexOf(item) === -1) this.push(item);
    
  3. pushUnique(item)
    Array.prototype.pushUnique = function (item){
        if(this.indexOf(item) === -1) {
            this.push(item);
            return true;
        return false;
    };
    
  4. pushUnique(item)
    Array.prototype.pushUnique = function (item) {
        if (this.indexOf(item) == -1) {
            this.push(item);
            return true;
        return false;
    };
    String.prototype.repeat = function (num) {
        return new Array(num + 1).join(this);
    ...
    
  5. pushUnique(item,unique)
    Array.prototype.pushUnique = function(item,unique)
      if(unique === false) {
        this.push(item);
      } else {
        if(this.indexOf(item) == -1)
          this.push(item);
    };
    ...