mirror of
https://github.com/Instadapp/Swap-Aggregator-Subgraph.git
synced 2024-07-29 21:57:12 +00:00
26 lines
442 B
JavaScript
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;
|
|
}
|