Problems › TypeScript › machines
Spares to keep for a fleet
To scale a fleet safely, buying 10% extra units as spares keeps the line alive while one fails. Return the total units to purchase.
- Spares are ten percent, rounded up — a single unit has to be available even for a tiny fleet.
- The answer is units plus the rounded-up spare count.
sparesForScale(units: int) → int
Where you start
function sparesForScale(units: number): number {
}
Worked examples
| Call | Result |
|---|---|
sparesForScale(100) | 110 |
sparesForScale(1) | 2 |
sparesForScale(0) | 0 |
sparesForScale(10) | 11 |
Hint
Ceiling of ten percent in integers is (units + 9) / 10.
Reference solution in TypeScript
function sparesForScale(units: number): number {
return units + Math.floor((units + 9) / 10);
}