Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fruits = [
- {name:'apple', price:20, total:0},
- {name:'banana', price:15, total:22},
- {name:'orange', price:13, total:23},
- {name:'melon', price:18, total:0}
- ]
- const newFruits = [
- {name:'sausage', price:33, total:50},
- {name:'cornedbeef', price:25, total:38},
- {name:'beeftuna', price:15, total:13}
- ]
- let substitution = (fruits, newFruits) => {
- let substitutedFruits = ''
- fruits.map( fruit => {
- newFruits.map( newFruit => {
- console.log(newFruit.name)
- if(fruit.total == 0 && !substitutedFruits.includes(newFruit.name)){
- Object.assign(fruit, newFruit)
- substitutedFruits += newFruit.name
- }
- })
- })
- }
- substitution(fruits, newFruits)
- console.table(fruits)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement