mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-30 08:50:32 +02:00
Remove lodash isNaN, isNumber, isString, bind, uniqBy
(re: 6087)
This commit is contained in:
@@ -45,6 +45,7 @@ export function utilArrayUniq(a) {
|
||||
return Array.from(new Set(a));
|
||||
}
|
||||
|
||||
|
||||
// Splits array into chunks of given chunk size
|
||||
// var a = [1,2,3,4,5,6,7];
|
||||
// utilArrayChunk(a, 3);
|
||||
@@ -89,3 +90,39 @@ export function utilArrayGroupBy(a, key) {
|
||||
}, {});
|
||||
}
|
||||
|
||||
|
||||
// Returns an Array with all the duplicates removed
|
||||
// where uniqueness determined by the given key
|
||||
// `key` can be passed as a property or as a key function
|
||||
//
|
||||
// var pets = [
|
||||
// { type: 'Dog', name: 'Spot' },
|
||||
// { type: 'Cat', name: 'Tiger' },
|
||||
// { type: 'Dog', name: 'Rover' },
|
||||
// { type: 'Cat', name: 'Leo' }
|
||||
// ];
|
||||
//
|
||||
// utilArrayUniqBy(pets, 'type')
|
||||
// [
|
||||
// { type: 'Dog', name: 'Spot' },
|
||||
// { type: 'Cat', name: 'Tiger' }
|
||||
// ]
|
||||
//
|
||||
// utilArrayUniqBy(pets, function(item) { return item.name.length; })
|
||||
// [
|
||||
// { type: 'Dog', name: 'Spot' },
|
||||
// { type: 'Cat', name: 'Tiger' },
|
||||
// { type: 'Cat', name: 'Leo' }
|
||||
// }
|
||||
export function utilArrayUniqBy(a, key) {
|
||||
var seen = new Set();
|
||||
return a.reduce(function(acc, item) {
|
||||
var val = (typeof key === 'function') ? key(item) : item[key];
|
||||
if (val && !seen.has(val)) {
|
||||
seen.add(val);
|
||||
acc.push(item);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user