I have an array of objects containing quantities. Each object includes a key indicating the amount to fill (amountToFill) and another key representing the already filled amount (amountFilled). The goal is to specify a quantity (amount: number = 50;) and automatically set the amountFilled to match the amountToFill, continuously reducing the value of (amount: number = 50) as the array gets filled until the amount: number equals 0.
When the amountFilled is greater than 0, caution must be taken when calculating the subtraction from the total amount.
Initial Outcome
amountArray =[{
option:'text',
amountToFill: 5,
amountFilled:0,
},
{
option:'text1',
amountToFill: 3,
amountFilled:1,
},
...
];
Desired Outcome
amountArray1 =[{
option:'text',
amountToFill: 5,
amountFilled:5,
filled: true
},
{
option:'text1',
amountToFill: 3,
amountFilled:3,
filled: true
},
...
];