Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function printProductAndQuantity(stock, ordered) {
- let collection = {};
- for (let i = 0; i < stock.length; i += 2) {
- // i += 2, за да вземаме по 2 елемента наведнъж
- collection[stock[i]] = Number(stock[i + 1]);
- }
- for (let j = 0; j < ordered.length; j += 2) {
- // проверка, ако стоката се повтаря
- if (Object.keys(collection).includes(ordered[j])) {
- // if (collection.hasOwnProperty(ordered[j])) {
- collection[ordered[j]] += Number(ordered[j + 1]);
- } else {
- collection[ordered[j]] = Number(ordered[j + 1]);
- }
- }
- for (let key in collection) {
- console.log(`${key} -> ${collection[key]}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment