Javascript Array getUnique()

Description

Javascript Array getUnique()


Array.prototype.getUnique = function(){
    var u = {}, a = [];
    for(var i = 0, l = this.length; i < l; ++i){
        if(u.hasOwnProperty(this[i])) {
            continue;//  ww  w  . j  a  va 2s .co m
        }
        a.push(this[i]);
        u[this[i]] = 1;
    }
    return a;
}

// console.log(Array, [].getUnique)

module.exports = Array;

Javascript Array getUnique()

Array.prototype.getUnique = function(){
   var u = {}, a = [];
   for(var i = 0, l = this.length; i < l; ++i){
      if(u.hasOwnProperty(this[i])) {
         continue;/*from   w  w  w.  j  a  v  a  2  s  .c o  m*/
      }
      a.push(this[i]);
      u[this[i]] = 1;
   }
   return a;
}

Javascript Array getUnique()

Array.prototype.getUnique = function(){
    var o = {}, a = [], i, e;
    for(i = 0; e = this[i]; i++){o[e] = 1};
    for(e in o) {a.push (e)};
    return a;/*w  w w.  java 2 s .  c  o  m*/
}

Javascript Array getUnique()

// http://stackoverflow.com/a/1961068/148668
Array.prototype.getUnique = function(){
   var u = {}, a = [];
   for(var i = 0, l = this.length; i < l; ++i){
      if(u.hasOwnProperty(this[i])) {
         continue;// w  w  w  .  ja  va2s .  co m
      }
      a.push(this[i]);
      u[this[i]] = 1;
   }
   return a;
}

Javascript Array getUnique()

Array.prototype.getUnique = function(){
  // add a comments
   var u = {}, a = [];
   for(var i = 0, l = this.length; i < l; ++i){
      if(u.hasOwnProperty(this[i])) {
         continue;//from w w w.  jav  a2s . c  o  m
      }
      a.push(this[i]);
      u[this[i]] = 1;
      alert('hoxfix is finished');
      alert('issu1 is fixed');
   }
   return a;
}

Javascript Array getUnique()

Array.prototype.getUnique = function(){
    var that = this;
    for (var i = 0; i < that.length; i++){
        for (var j = i+1; j < that.length; j++){
            if(that[i] === that[j]){
                that.splice(j, 1);//from  w w w .  ja  v  a 2s.  com
                j--;
            }
        }
    }
    return that;
};

Javascript Array getUnique()

Array.prototype.getUnique = function() {
 var arr = [];/*from w  w w  .j a  va2 s . c om*/

 this.forEach(function(a) {
  if (arr.indexOf(a) < 0) {
   arr.push(a);
  }
 });

 return arr;
};

Javascript Array getUnique()

Array.prototype.getUnique = function(){
   var u = {}, a = [];
   for(var i = 0, l = this.length; i < l; ++i){
      if(u.hasOwnProperty(this[i])) {
         continue;/*from  ww w  .j  a va 2  s.  c om*/
      }
      a.push(this[i]);
      u[this[i]] = 1;
   }
   return a;
}


for (var i = 1; i<101; i++) {
  var nodeId = Math.round(getRandom(1,3));
  var jobTime = Math.round(getRandom(1,100)) * 10;

 // var resources = Math.round(getRandom(1,5));

  var resources = [] ;
  resources.push(Math.round(getRandom(0,4)));
  resources.push(Math.round(getRandom(0,4)));
  resources.push(Math.round(getRandom(0,4)));


  console.log(i + ":" + nodeId + ":" + jobTime + ":" + resources.getUnique().join("#") );
}

function getRandom(min, max) {
  return Math.random() * (max - min) + min;
}



PreviousNext

Related