title: Reducing a gift cards array
body: <p>In an eCommerce site I'm building, I allow users to manage gift cards, each user who purchases a gift card, gets a gift card object pushed into a database. For example, a user would have a bunch of gift cards like so:</p>
  <pre><code>const giftcards = [
    {amount: 20, id: 1, ....}, 
    {amount: 23, id: 2, ...}
   ]
  </code></pre>
  <p>Now at checkout, if the sum of the <code>giftcards</code> amount is greater than the total price (at checkout), I would like to loop through the <code>giftcards</code> array and subtract the amount or remove the gift card if the price of the cost is greater than one <code>giftcard</code>, then continue the process until the amount paid by the gift cards are equal, and of course, save a new copy of the edited gift card array</p>
  <pre><code>For example, if the total were to be
  const total = 40
  </code></pre>
  <p>Then the new <code>giftcards</code> array should look like:</p>
  <pre><code>const giftcards = [
    {amount: 3, id: 2, ...}
   ]
  </code></pre>
  <p>EDIT:</p>
  <pre><code> function reduceGiftCards(amount) {
   for(let i = 0; i &lt; giftcards.length; i++) {
     if(amount &gt; giftcards[i].amount) {
       giftcards[i].amount = 0
       amount = amount - giftcards[i].amount
     }
   }
   console.log(giftcards)
   }
      reduceGiftCards(40)
  </code></pre>
  <p>//when logged, all gift cards are given a value of 0</p>