Drill

ProblemsJavaScript › finance

Price per unit

easyfinanceJavaScript

A bulk bin lists a total for a quantity of identical items. What does a single unit cost?

pricePerUnit(totalMinor: int, quantity: int) → int

Solve it in the editor →

Where you start

function pricePerUnit(totalMinor, quantity) {
  
}

Worked examples

CallResult
pricePerUnit(1000, 4)250
pricePerUnit(1000, 3)333
pricePerUnit(100, 10)10
pricePerUnit(0, 5)0

Hint

Divide and drop the remainder.

Reference solution in JavaScript
function pricePerUnit(totalMinor, quantity) {
  if (quantity <= 0) return 0;
  return Math.floor(totalMinor / quantity);
}

The same problem in another language

More finance problems in JavaScript