Nodejs Array Unique uniq()

Here you can find the source of uniq()

Method Source Code

// functional sort
Object.defineProperty(Array.prototype, 'uniq', {
    enumerable: false,//from  ww w  .  jav  a  2  s  .  co  m
    value: function() { return [...new Set(this)] }
});


console.log([1,2,3,3,3,2,4].uniq())

Related

  1. uniq()
    Array.prototype.uniq = function () {
      return [...new Set(this)];
    };
    
  2. uniq()
    Array.prototype.uniq = function() {
      return this.filter(function(value, index) {
        return this.indexOf(value) == index;
      }.bind(this));
    };
    
  3. uniq()
    Array.prototype.uniq = function(){
      var uniqueness = [];
      for(var i = 0; i < this.length; i++){
        var element = this[i];
        if (this.indexOf(element) === this.lastIndexOf(element) || uniqueness.indexOf(element) === -1){
          uniqueness.push(this[i]);
      return uniqueness;
    ...
    
  4. uniq()
    Array.prototype.uniq = function() {
      var u = {}, a = [];
      for (var i = 0, ii = this.length; i < ii; i++) {
        if (u.hasOwnProperty(this[i])) {
          continue;
        a.push(this[i]);
        u[this[i]] = 1;
      return a;
    };