Nodejs Array Distinct distinct()

Here you can find the source of distinct()

Method Source Code

Array.prototype.distinct = function(){
   for(var i = 0;i < this.length;i++){
      for(var j = i+1;j < this.length;){
         if(this[j] === this[i]){
         for(var k = j;k < this.length;k++){
            this[k] = this[k + 1];//from   w  w  w  .j ava2  s  . c  o  m
         }
            delete this[this.length - 1];
            this.length--;
            
         }else{
            j++;
         }
      }
   }
   return this;
};

Related

  1. distinct()
    "use strict";
    Array.prototype.distinct = function () { 
      return Array.from(new Set(this)); 
    };
    
  2. distinct()
    Array.prototype.distinct = function () {
      var d = {},
        i;
      this.push(d);
      while ((i = this.shift()) != d) {
        if (!d.hasOwnProperty(i)) {
          this.push(i);
          d[i] = 1;
      return this;
    };
    
  3. distinct()
    Array.prototype.distinct = function() {
        var ret = [];
        for (var i = 0; i < this.length; i++) {
            for (var j = i + 1; j < this.length; ) {
                if (this[i] === this[j]) {
                    ret.push(this.splice(j, 1)[0]);
                } else {
                    j++;
        return ret;
    };
    console.log([1, 2, 3, 4, 4, "4", 5].distinct());
    
  4. distinct()
    Array.prototype.distinct = function(){
      for(var i = 0; i< this.length; i++){
        var n = this[i];
        this.splice(i, 1);
        if(this.indexOf(n) < 0){
          this.splice(i,1,n);
      return this;
    ...
    
  5. distinct()
    Array.prototype.distinct = function() {
        var hash = {};
        var a = [];
        for(var i = 0; i < this.length; i++) {
            if(hash.hasOwnProperty(this[i])) {
                continue;
            hash[this[i]] = true;
            a.push(this[i]);
    ...
    
  6. distinct()
    Array.prototype.distinct = function () {
        var result = new Array();
        this.forEach(x => {
            if (!result.contains(x))
                result.push(x);
        });
        return result;
    };
    
  7. distinct()
    Array.prototype.distinct = function(){
      var self = this
      var _array = []
      self.forEach(function(e){
        if(_array.contains(e)){
          _array.push(e)
      })
      return _array
    ...
    
  8. distinct()
    Array.prototype.distinct = function () {
      var result = [];
      var hash = new Dictionary();
      forEach(this, function (element) {
        if (!hash.contains(element)) {
          result.push(element);
          hash.store(element, element);
      });
    ...