open-nomad/ui/app/helpers/dedupe-by-property.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

16 lines
413 B
JavaScript
Raw Normal View History

// Takes an array and a property name and returns a new array with all the duplicates removed.
import { helper } from '@ember/component/helper';
export default helper(function dedupeByProperty([arr], { prop }) {
const seen = new Set();
return arr.filter((item) => {
const val = item[prop];
if (seen.has(val)) {
return false;
} else {
seen.add(val);
return true;
}
});
});