Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function printStock(stock, orderedProducts) {
- let currentStock = {};
- stock.forEach((e, index) => {
- if (index % 2 == 0) {
- if (!currentStock[e]) {
- currentStock[e] = Number(stock[index + 1]);
- } else {
- currentStock[e] += Number(stock[index + 1]);
- }
- }
- });
- orderedProducts.forEach((el, index) => {
- if (index % 2 == 0) {
- if (!currentStock[el]) {
- currentStock[el] = Number(orderedProducts[index + 1]);
- } else {
- currentStock[el] += Number(orderedProducts[index + 1]);
- }
- }
- });
- Object.keys(currentStock)
- .forEach(product => console.log(`${product} -> ${currentStock[product]}`));
- }
Advertisement
Add Comment
Please, Sign In to add comment