I'm stuck on a problem and I've no idea in which direction should I go. There is a array of objects and I want to check if there was previously exact type, if so then copy the properites and add new one without a type property, if not push the object to the array.
Expected input:
const arr = [
{type: 1, amount: 100},
{type: 2, amount: 200},
{type: 3, amount: 300},
]
const obj = {type: 1, name: 'PLN'}
Expected output:
arr = [
{type: 1, amount: 100, name: 'PLN'},
{type: 2, amount: 200},
{type: 3, amount: 300},
]
Expected input:
const arr = [
{type: 1, amount: 100},
{type: 2, amount: 200},
{type: 3, amount: 300},
]
const obj = {type: 4, amount: 400}
Expected output:
arr = [
{type: 1, amount: 100},
{type: 2, amount: 200},
{type: 3, amount: 300},
{type: 4, amount: 400},
]
If something is unclear please let me know :)