Nodejs Array Unique unique()

Here you can find the source of unique()

Method Source Code

Array.prototype.unique = function () {
  var o = new Object();
  var i, e;//from   ww  w  .  java  2 s .  co  m
  
  for (i = 0; e = this[i]; i++) {
    o[e] = 1
  };
  
  var a = new Array();
  for (e in o) {
    a.push (e)
  };
  
  return a;
}

Related

  1. unique()
    Array.prototype.unique=function(){
        return this.filter(function (x,i,self){
            return self.indexOf(x)===i;
        });
    
  2. unique()
    Array.prototype.unique = function() {
       return this.sort().reduce( (a,e) => e === a[a.length-1] ? a : (a.push(e), a), [] )
    
  3. unique()
    Array.prototype.unique=function(){
      var n=[];
      for(var i=0;i<this.length;i++){
        if(n.indexOf(this[i])==-1) n.push(this[i]);
      return n;
    
  4. unique()
    Array.prototype.unique = function (){
      return Array.from(new Set(this));
    let testArray = [1,2,5,4,2,6,1];
    console.log(testArray.unique());
    
  5. 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) r.push(o[i]);
      return r;
    };
    
  6. unique()
    Array.prototype.unique = function(){
      'use strict';
      this.sort();
      var ret = [this[0]];
      for(var index=0; index < this.length; index++){
        if(this[index] != ret[ret.length - 1]){
          ret.push(this[index]);
      return ret;
    };
    
  7. unique()
    Array.prototype.unique = function()
        var n = {},r=[];
        for(var i = 0; i < this.length; i++)
            if (!n[this[i]])
                n[this[i]] = true;
                r.push(this[i]);
    ...
    
  8. 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;
    ...
    
  9. 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;
    ...