Skip to content

Instantly share code, notes, and snippets.

@ianjsikes
Created May 3, 2019 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianjsikes/bc4466e622c41aeb9047e852c96626ca to your computer and use it in GitHub Desktop.
Save ianjsikes/bc4466e622c41aeb9047e852c96626ca to your computer and use it in GitHub Desktop.
export const dedupItems = (
items: DumplingItem[]
): [DumplingItem[], DumplingItem[]] => {
let dupeItems = [];
let newItems = [];
for (const item of items) {
let i = newItems.findIndex(({ sellerId }) => sellerId === item.sellerId);
if (i !== -1) {
dupeItems.push(item);
newItems[i].categories.push(...item.categories);
newItems[i].categories = _.uniq(newItems[i].categories);
} else {
newItems.push(item);
}
}
return [newItems, dupeItems];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment