Nodejs Array Unique unique()

Here you can find the source of unique()

Method Source Code

Array.prototype.unique = function() {
  return this.filter(function(item, idx, array) {
    return array.indexOf(item) === idx;
  });/*from  ww  w .j ava  2  s  .c o  m*/
}

Related

  1. unique()
    Array.prototype.unique = function() {
      var o = {}, i, l = this.length, r = [];
      for(i=0; i<l;i+=1) o[this[i]] = this[i];
      for(i in o) {
        if (o[i]) {
          r.push(o[i]);
      return r;
    ...
    
  2. unique()
    Array.prototype.unique = function() {
      return this.filter( function(value, index, self) { 
        return self.indexOf(value) === index;
      } );
    };
    
  3. unique()
    Array.prototype.unique = function () {
        var r = new Array();
        o:for(var i = 0, n = this.length; i < n; i++)
          for(var x = 0, y = r.length; x < y; x++)
            if(r[x]==this[i])
              continue o;
    ...
    
  4. unique()
    Array.prototype.unique = function() {
        var a = [];
        for (var i=0, l=this.length; i<l; i++)
            if (a.indexOf(this[i]) === -1)
                a.push(this[i]);
        return a;
    };
    
  5. unique()
    Array.prototype.unique = function() {
        var a = this.concat();
        for(var i=0; i<a.length; ++i) {
            for(var j=i+1; j<a.length; ++j) {
                if(a[i] === a[j])
                    a.splice(j--, 1);
        return a;
    ...
    
  6. unique()
    Array.prototype.unique = function(){
        var array = [];
        for(var i = 0; i < this.length; i++) {
            if(!array.contains(this[i])) {
                array.push(this[i]);
        return array.compact();
    };
    ...
    
  7. unique()
    Array.prototype.unique = function() {
      var uniques = [];
      this.forEach(function(value) {
        if (uniques.indexOf(value) == -1)
          uniques.push(value);
      });
      return uniques;
    };
    
  8. unique()
    Array.prototype.unique = function() {
      return this.reduce(function(prev_val, current_val) {
        if (prev_val.indexOf(current_val) < 0) {
          prev_val.push(current_val);
        return prev_val;
      }, []);
    };
    Array.prototype.times_do = function(callback) {
    ...
    
  9. unique()
    Array.prototype.unique = function() {
        var a = [];
        for (var i = 0, l = this.length; i < l; i++)
            if (a.indexOf(this[i]) === -1)
                a.push(this[i]);
        return a;