Created
January 11, 2019 16:33
-
-
Save Jalson1982/fb4dd6e220375bd8393c1ebed8e250b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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