Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this.Dedupe = class Dedupe {
- constructor(createKey, compare) {
- this.createKey = createKey || this.defaultCreateKey;
- this.compare = compare || this.defaultCompare;
- }
- defaultCreateKey(item) {
- return item;
- }
- defaultCompare() {
- return false;
- }
- one(values) {
- const valueMap = new Map();
- values.forEach(value => {
- const key = this.createKey(value);
- if (!valueMap.has(key) || this.compare(valueMap.get(key), value)) {
- valueMap.set(key, value);
- }
- });
- return Array.from(valueMap.values());
- }
- };
- this.EXPORTED_SYMBOLS = ["Dedupe"];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement