title: Avoid duplicate code when api might return array or single object
body: <p>I'm working with an API to consult car debits. If the car has more than one debit, the API returns an array of debits. If it has only one, it returns a single debit object (not an array with one element).<br />
  The problem is that I have to duplicate all the deserialization of this response checking whether the attribute is an array or a single object.</p>
  <pre class="lang-js prettyprint-override"><code>const debits = []
  if (car.debits.length &gt; 0) {
      car.debits.forEach((debit: any) =&gt; {
          debits.push({
              id: uuidv1(),
              description: debit.description,
              label: debit.label,
              amount: parseInt(debit.amount, 10)
          })
      })
  
  } else {
      debits.push({
          id: uuidv1(),
          description: debit.description,
          label: debit.label,
          amount: parseInt(debit.amount, 10)
      })
  }
  </code></pre>
  <p>Is there any way to simplify this? I showed just a small example but the object is much larger and there are many other attributes that I have to do the same.</p>