Last active
December 22, 2015 18:39
-
-
Save tusharmath/6514784 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function getDistinctObjArray(arr) { | |
var distinctArr = arr.filter(function(el) { | |
var isDup = el.inArray; | |
el.inArray = true; | |
return !isDup; | |
}); | |
distinctArr.forEach(function(el) { | |
delete el.inArray; | |
}); | |
return distinctArr; | |
} | |
var p = [{ | |
a: 1 | |
}, { | |
a: 1 | |
}, { | |
a: 1 | |
}, { | |
b: 1 | |
}, { | |
b: 1 | |
}, { | |
a: 1 | |
}, { | |
c: 1 | |
}, { | |
a: 1 | |
}, { | |
d: 1 | |
}, { | |
a: 1 | |
}, | |
]; | |
var x = getDistinctObjArray(p); | |
if(p.length === x.length) | |
alert('Duplicates were not removed'); | |
else | |
alert('Dupilcates were removed'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment