c# - AngularJs Filter to Remove duplicates using Check two Key values -


i have collection has 2 keys below angularjs model.

$scope.collection=[{id:1,name:"a"},{id:1,name:"b"},{id:1,name:"a"},{id:1,name:"c"},{id:2,name:"a"},{id:2,name:"c"},{id:2,name:"a"},{id:3,name:"d"}]; 

i want remove duplicate rows, if both keys have same values , wanted array without duplicate rows using angularjs filter.

sample output should below

$scope.collection=[{id:1,name:"a"},{id:1,name:"b"},{id:1,name:"c"},{id:2,name:"a"},{id:2,name:"c"},{id:3,name:"d"}] 

a possible solution (base angularjs):

.filter('remover', function () {     return function ( items ) {          //filtering duplicates...         var filtered = {};         ( var = 0; < items.length; i++ ) {            if(filtered[items[i].id] == undefined)               filtered[items[i].id] = [];             if(filtered[items[i].id].indexof(items[i].name) != -1)               filtered[items[i].id].push(items[i].name);         }          //new array filtered elements         var array = [];         for(var id in filtered){            array.push({id: id, name: filtered[id]});         }          return filtered;     }         } ); 

this should Θ(2n) because iterate twice array: beware use big loads of data.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -