open-nomad/ui/app/helpers/dedupe-by-property.js
Phil Renaud 7a1560e509
[ui] Service health check in-session history (#14515)
* Preliminary version

* Addition of a filtering helper and more styling for service check history

* Fixed-widths on table cols

* Account for new rows in test

* Explanation for magic numbers
2022-09-12 22:10:43 -04:00

16 lines
413 B
JavaScript

// 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;
}
});
});