Ad
  • Custom User Avatar

    Kucharskimaciej your comment above is incorrect. +v is not an equivalent of parseInt(v, 10). It is, in fact, an equivalent of Number(v). The '+' operator is a shorthand to coerce each 'v' from a string to a number.

    This might seem like splitting hairs, but it’s a critical point for others to understand this shorthand in a broader context.

    In the solution above, we see that 'int' is already coerced into a number because of the *256. If we step through the first loop of the reduce method without coercing 'v', we can see how the sum would change — 128 * 256 + "32" // "3276832" (INCORRECT) vs 128 * 256 + 32 // 32800 (CORRECT). Without coercing 'v' you actually coerce 'int' back into a string and concatenate 'v'

  • Custom User Avatar

    If what you are saying is true, then the author needs to make it more clear that $50 or $100 amounts are bills that cannot be broken at a later point.

    Just because a customer needs change for $50, doesn’t automatically mean we would be presented with one single bill.