Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function storeProvisions(storeProducts, purchasedProducts) {
- const finalList = {};
- const storeLength = storeProducts.length;
- for (let i = 0; i < storeLength; i += 2) {
- const product = storeProducts[i];
- const quantity = Number(storeProducts[i+1]);
- finalList[product] = quantity;
- }
- const purchasedLength = purchasedProducts.length;
- for (let j = 0; j < purchasedLength; j += 2) {
- if (purchasedProducts[j] in finalList) {
- finalList[purchasedProducts[j]] += Number(purchasedProducts[j+1]);
- } else {
- finalList[purchasedProducts[j]] = Number(purchasedProducts[j+1]);
- }
- }
- for (let [key, value] of Object.entries(finalList)) {
- console.log(`${key} -> ${value}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment