Nodejs Array Delete deleteSame()

Here you can find the source of deleteSame()

Method Source Code

function JsonSort(json,key){
    for(j=1;j < json.length;j++){
        var temp = json[j],
            val  = temp[key],//  w w  w .java 2  s .  c o m
            i    = j-1;
        while(i >=0 && json[i][key]>val){
            json[i+1] = json[i];
            i = i-1;
        }
        json[i+1] = temp;

    }
    return json;
}
Array.prototype.deleteSame = function(){
   var res = [this[0]];
   for(var i = 1; i < this.length; i++){
      var repeat = false;
      for(var j = 0; j < res.length; j++){
         if(this[i] == res[j]){
            repeat = true;
            break;
         }
      }
      if(!repeat){
         res.push(this[i]);
      }
   }
   return res;
}

Related

  1. del(index)
    Array.prototype.del = function(index){
        if(isNaN(index) || index > this.length || index < 0){
            return false;
        this.splice(index,1);
    
  2. del(n)
    Array.prototype.del=function(n) {
      if(n<0){
        return this;
      }else{
        return this.slice(0,n).concat(this.slice(n+1,this.length));
    
  3. deleteRepeat()
    Array.prototype.deleteRepeat = function(){
      var arr = this, 
        result=[], 
        flag; 
      for(var i=0;i<arr.length;i++){
        flag=true;
        for(var j=0;j<result.length;j++){
          if(result[j]===arr[i]){
            flag=false;
    ...
    
  4. trim(deleteValue)
    Array.prototype.trim = function(deleteValue) {
      var i;
      for (i = 0; i < this.length && this[i] == deleteValue;) {
        this.splice(i, 1);
      for (i = this.length-1; i >= 0 && this[i] == deleteValue; --i) {
        this.splice(i, 1);
      return this;
    ...