Porting the Translation Desk’s Quote Pipeline
You ported part of the translation desk’s quote script to JavaScript. The desk counts the
words in a museum guide, prices each request in pence per word, records every request, never
calculates an identical price twice, and formats pence in the desk’s currency. This part prints five
lines. Python gets the counts from two decorators on two functions. JavaScript has no @ line, so you
place each wrapper, and the counts must come out the same.
The project folder, translation-desk/, has a package.json with { "type": "module" }, so Node
treats desk.js and helpers.js as ES modules, and desk.js imports from helpers.js. withAudit
is the wrapper that keeps its receiver, in place of Python’s with_audit.
Python caches with lru_cache. JavaScript has no built-in memoizer, so memoizePrice keys a Map by
both inputs, through JSON.stringify([words, ratePence]), because a Map matches arrays by identity,
not by value the way lru_cache matches arguments. It only suits a pure calculation with two
whole-number inputs.
Python decorates price with @lru_cache. JavaScript has no @ line for a function, so you pass the
arrow to memoizePrice and keep what it returns. The arrow adds one to calculations each time it
really runs: Python needs a global statement for that, and JavaScript assigns the outer let
directly. The calculation reads only its two arguments, never this or the desk, so it’s safe to
cache by those two inputs alone.