Skip to content

Instantly share code, notes, and snippets.

@tusharmath
Last active December 22, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tusharmath/6514784 to your computer and use it in GitHub Desktop.
Save tusharmath/6514784 to your computer and use it in GitHub Desktop.
'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