Nodejs Array Distinct distinct2()

Here you can find the source of distinct2()

Method Source Code

Array.prototype.distinct2 =  function(){
   var _self = this;
   var _a = this.concat().sort(); 
   console.log(_a);//from w  ww.  j  a v a2  s .  c o  m

   _a.sort(function(a,b){
      console.log("a: "+ a, "b: "+ b);
      if(a == b){
         var n = _self.indexOf(a);
         _self.splice(n, 1);
      }
   });
   return _self;
}

Related

  1. distinct()
    Array.prototype.distinct = function () {
        var result = new Array();
        this.forEach(x => {
            if (!result.contains(x))
                result.push(x);
        });
        return result;
    };
    
  2. distinct()
    Array.prototype.distinct = function(){
      var self = this
      var _array = []
      self.forEach(function(e){
        if(_array.contains(e)){
          _array.push(e)
      })
      return _array
    ...
    
  3. 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);
      });
    ...
    
  4. distinct()
    Array.prototype.distinct = function () {
        var sameObj = function (a, b) {
            var tag = true;
            if (!a || !b) return false;
            for (var x in a) {
                if (!b[x])
                    return false;
                if (typeof (a[x]) === 'object') {
                    tag = sameObj(a[x], b[x]);
    ...
    
  5. distinct(comparer)
    Array.prototype.distinct = function (comparer) {
      var arr = [];
      var l = this.length;
      for (var i = 0; i < l; i++) {
        if (!arr.contains(this[i], comparer))
          arr.push(this[i]);
      return arr;
    };
    ...