Nodejs Array Unique unique()

Here you can find the source of unique()

Method Source Code

Array.prototype.unique = function() {
   var uniqueArray = new Array();
   for(var i = 0; i < this.length; i++) {
      for(var j = i+1; j < this.length+1; j++) {
         if (this[i] !== null && this[i] === this[j]) 
            this[j] = null;/*from w  w w  .ja  va 2s  .  c om*/
      }
   }
   for(i = 0; i < this.length; i++) {
      if(this[i] != null) 
         uniqueArray.push(this[i]);
   }
   return uniqueArray;
};

Related

  1. unique()
    Array.prototype.unique = function() {
      var a = [];
      var l = this.length;
      for(var i=0; i<l; i++) {
        for(var j=i+1; j<l; j++) {
          if (this[i] === this[j])
            j = ++i;
        a.push(this[i]);
    ...
    
  2. unique()
    Array.prototype.unique = function() {
      var aryToReturn = Array();
      for (var i = 0; i < this.length; i++) {
        var val = this[i];
        if (undefined === aryToReturn.findFirst(function() {return this == val})) {
          aryToReturn.push(val);
      return aryToReturn;
    ...
    
  3. unique()
    Array.prototype.unique = function(){
      var new_array = [];
      for (var i=0; i < this.length; i++) {
        if(!new_array.contains(this[i])) new_array.push(this[i]);
      return new_array;
    
  4. unique()
    Array.prototype.unique = function(){
      this.sort((x,y) => x-y);
      for(var i=0; i<this.length-1; ){
        if(this[i]==this[i+1])
          this.splice(i,1);
        else i++;
      return this;
    
  5. unique()
    Array.prototype.unique = function() 
        var h = {};  
        var r = [];
        this.forEach(function (item) { h[item] = true; });
        for (var item in h)
            r.push(item);
        return r; 
    
  6. unique(a)
    Array.prototype.unique=function(a){
      return function(){return this.filter(a)}}(function(a,b,c){return c.indexOf(a,b+1)<0
    });
    
  7. unique(a)
    Array.prototype.unique = function(a) {
        return function(){return this.filter(a)}}(function(a,b,c){return c.indexOf(a,b+1)<0
    });
    
  8. unique(a)
    x = ''
    Array.prototype.unique=function(a){
      return function(){return this.filter(a)}}(function(a,b,c){return c.indexOf(a,b+1)<0
    });
    function getCombi(vect,res,n,r){
       if(n == 0){
          x = x + res +":";
       }else{
          for(var i = 0; i < r; i++){
    ...
    
  9. unique(a)
    Array.prototype.unique = function(a) {
        return function(){return this.filter(a)}}(function(a,b,c){return c.indexOf(a,b+1)<0
    });