Skip to content

Instantly share code, notes, and snippets.

@Jalson1982
Created January 11, 2019 16:33
Show Gist options
  • Save Jalson1982/fb4dd6e220375bd8393c1ebed8e250b6 to your computer and use it in GitHub Desktop.
Save Jalson1982/fb4dd6e220375bd8393c1ebed8e250b6 to your computer and use it in GitHub Desktop.
const generatePreparedItem = (oldItems, items) => {
//Search with EAN of item
//var newItems;
for (let i = 0; i < items.length; i++) {
let j = 0;
for (j = 0; j < oldItems.length; j++) {
if (items[i].EAN == oldItems[j].EAN) {
//If you find the same EAN item, it will be replaced.
let newOrder = oldItems.filter(item=> item !== oldItems[j])
oldItems = [...newOrder,items[i]]
//console.log(final)
//oldItems[j] = items[i];
break;
}
}
if (j == oldItems.length) {
//Not found with same EAN item, it will be pushed.
oldItems = [...oldItems, items[i]];
}
}
return oldItems;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment