code: function addBase(next, base, add, degree) {
    for (const ud of add) {
      const units = ud.unit.units;
      if (units) {
        next = addBase(next, base, units.base.components, degree * ud.degree);
      } else {
        for (var i = 0; i < next; i++) {
          const bud = base[i];
  
          if (bud.unit === ud.unit) {
            bud.degree += ud.degree * degree;
            break;
          }
        }
  
        if (i === next) {
          base[next++] = new UnitDegree(ud.unit, ud.degree * degree);
        }
      }
    }
  
    return next;
  }
docs: Base Analysis