Your describeDock() now takes bike and free-slot counts. The crew lead also wants each dock’s fill rate. Keep that formula in a helper so every report line uses the same calculation. JavaScript’s arrow syntax suits this small function.
Write the Fill Rate as an Arrow
The calculations here assume non-negative bike and free-slot counts with a positive combined capacity.
In Python, you’d use def for a named helper. Python’s lambda and JavaScript’s arrow function, a function written with =>, offer these expression forms:
| Python | JavaScript |
|---|---|
lambda bikes, slots: bikes / (bikes + slots) * 100 |
(bikes, slots) => bikes / (bikes + slots) * 100 |
fill_rate(14, 1) |
fillRate(14, 1) |
The arrow needs no keyword. Its parameters precede =>, and an expression body returns its value automatically. Store the function in a variable declared with const and call it normally. Replace ~/dock-report/dock-report.js with: