With Math.floor() in place of //, the port of batch_plan.py counts three full batches. The head roaster also needs the last part batch, which Python gets from %. JavaScript’s % agrees for the planner’s weights. With a positive divisor, the two part ways once the left side goes negative.
Port the Last Part Batch
Python’s last_batch_kg = green_kg % DRUM_KG ports with only the usual const and camelCase changes, and like Python’s, JavaScript’s % works on decimals:
Language: JavaScript
const DRUM_KG = 12;
const greenKg = 37.5 / (1 - 0.15);
const fullBatches = Math.floor(greenKg / DRUM_KG);
const lastBatchKg = greenKg % DRUM_KG;
console.log(`Batches: ${fullBatches} full + ${lastBatchKg} kg`);
Both scripts print the same line:
Language: Program Output
Batches: 3 full + 8.117647058823529 kg