You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
446 B
JavaScript
18 lines
446 B
JavaScript
'use strict';
|
|
|
|
const deepEql = require("deep-eql");
|
|
|
|
module.exports = function deeplyUnique(items) {
|
|
return items.reduce((uniques, item) => {
|
|
let index = uniques.findIndex((uniqueItem) => {
|
|
return (uniqueItem.type === item.type && deepEql(uniqueItem.data, item.data));
|
|
});
|
|
|
|
if (index === -1) {
|
|
return uniques.concat([item]);
|
|
} else {
|
|
return uniques;
|
|
}
|
|
}, []);
|
|
}
|