Drill

ProblemsTypeScript › production

How many batches to run

easyproductionTypeScript

The mixer takes a fixed number of units per batch, and a part-full batch still has to be run.

batchesNeeded(units: int, perBatch: int) → int

Solve it in the editor →

Where you start

function batchesNeeded(units: number, perBatch: number): number {
  
}

Worked examples

CallResult
batchesNeeded(100, 25)4
batchesNeeded(101, 25)5
batchesNeeded(1, 25)1
batchesNeeded(0, 25)0

Hint

Ceiling division in integers: (units + perBatch - 1) / perBatch.

Reference solution in TypeScript
function batchesNeeded(units: number, perBatch: number): number {
  if (units <= 0 || perBatch <= 0) return 0;
  return Math.floor((units + perBatch - 1) / perBatch);
}

The same problem in another language

More production problems in TypeScript