Swap-Aggregator-Subgraph/node_modules/unique-by/index.js
Richa-iitr d211083153 Revert "Revert "added handler""
This reverts commit c36ee8c5ca.
2022-07-03 07:30:05 +05:30

26 lines
442 B
JavaScript

'use strict';
module.exports = uniqueBy;
function uniqueBy(arr, getValue) {
var unique = [];
var found = {};
if (typeof getValue !== 'function') {
var key = getValue;
getValue = function defaultGetValue(obj) {
return obj[key];
};
}
arr.forEach(function addUniques(obj) {
var value = getValue(obj);
if (!found[value]) {
found[value] = true;
unique.push(obj);
}
});
return unique;
}