@adaptabletools/adaptable-cjs
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
26 lines (25 loc) • 835 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = uniqBy;
/**
* This method is like `uniq` except that it accepts iteratee which is
* invoked for each element in array to generate the criterion by which
* uniqueness is computed. The order of result values is determined by the
* order they occur in the array. The iteratee is invoked with one argument: (value).
* Drop-in replacement for lodash/uniqBy.
*/
function uniqBy(array, iteratee) {
const seen = new Set();
const result = [];
const fn = typeof iteratee === 'function'
? iteratee
: (value) => value?.[iteratee];
for (const item of array) {
const key = fn(item);
if (!seen.has(key)) {
seen.add(key);
result.push(item);
}
}
return result;
}