2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-09-13 02:10:43 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|