Advertisement
andreadc

substitutionFruits.js

May 5th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fruits = [
  2.     {name:'apple', price:20, total:0},
  3.     {name:'banana', price:15, total:22},
  4.     {name:'orange', price:13, total:23},
  5.     {name:'melon', price:18, total:0}
  6. ]
  7.  
  8. const newFruits = [
  9.     {name:'sausage', price:33, total:50},
  10.     {name:'cornedbeef', price:25, total:38},
  11.     {name:'beeftuna', price:15, total:13}
  12. ]
  13.  
  14. let substitution = (fruits, newFruits) => {
  15.     let substitutedFruits = ''
  16.     fruits.map( fruit => {
  17.         newFruits.map( newFruit => {
  18.             console.log(newFruit.name)
  19.             if(fruit.total == 0 && !substitutedFruits.includes(newFruit.name)){
  20.                 Object.assign(fruit, newFruit)
  21.                 substitutedFruits += newFruit.name
  22.             }
  23.         })
  24.     })
  25. }
  26.  
  27. substitution(fruits, newFruits)
  28. console.table(fruits)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement