Skip to content

Instantly share code, notes, and snippets.

@anantl05
Created September 25, 2018 07:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anantl05/d2180c0aeae10456ace881336f824073 to your computer and use it in GitHub Desktop.
Save anantl05/d2180c0aeae10456ace881336f824073 to your computer and use it in GitHub Desktop.
//Pass the orderItems array that you get
getDataArray(arr) {
const uniqByArr = uniqBy(arr, 'item_id');
let finalArr = [];
uniqByArr.map((item,idx) => {
const item_id = item.item_id;
let qty = 0;
arr.map((actualItem) => {
if (item_id === actualItem.item_id) {
qty += 1;
}
})
const obj = {...item};
obj.quantity = qty;
finalArr.push(obj);
})
return finalArr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment