Untitled
unknown
plain_text
a year ago
1.2 kB
5
Indexable
function getUniqueElements() {
const arr = [
{
id: 36,
business_name: 'Hydro Plumbing Solutions'
},
{
id: 107,
business_name: 'Hydro Plumbing Solutions (NSW)'
},
{
id: 108,
business_name: 'Hydro Plumbing Solutions (NSW)'
},
{
id: 109,
business_name: 'Hydro Plumbing Solutions (NSW)'
}
];
const seen = new Set();
return arr.filter(item => {
const key = item.business_name;
const isDuplicate = seen.has(key);
seen.add(key);
return !isDuplicate;
});
}
function getUniquesPart2() {
const existing_org_in_except_project = [
{
id: 21,
business_name: 'Hydro Plumbing Solutions'
},
{
id: 20,
business_name: 'Hydro Plumbing Solutions (NSW)'
},
]
// yang sudah ke-filter
const uniques = getUniqueElements()
return uniques.filter(unique => {
const match = existing_org_in_except_project.find(item => item.business_name === unique.business_name);
// If there's no match or the id in uniques is not greater, keep the item
return !match || unique.id <= match.id;
});
}
console.log(getUniquesPart2())Editor is loading...
Leave a Comment