Novicesyntax & basics
The Weighbridge at the Wool Market
The wool market's weighbridge is honest to a fault: it reports a fleece-load in stones with whatever fraction it finds. The toll clerk's ledger, however, has room only for whole stones, and the guild's rule for filling it is fixed — write the nearest whole number of stones, and when a load sits exactly halfway between two whole numbers, write the larger one.
Write wholeStones(weight).
weightis a number (possibly with a fractional part), and is never negative.- Return an integer: the whole number of stones the clerk writes in the ledger, being the nearest whole number to
weight, with an exact half rounding upward.
examples
- case 1
weight of 4.24 - case 2
weight of 2.53 (an exact half goes up, never down) - case 3
weight of 0.51 - case 4
weight of 99
- reward
- 140 XP
- signature
wholeStones
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- fraction below a half rounds down
- exact half rounds up
- another exact half rounds up
- fraction above a half rounds up
- just under a half rounds down
- smallest half is still a half
- an empty cart
- already a whole number of stones