Café Linde’s 180-word menu arrives with no boxes ticked on the quote form. Python’s defaults already cover quote(180). Your JavaScript port takes named options but still expects an object. You’ll let callers omit it and pass options between functions without repeating their names.
Leave the Options Out
The destructuring pattern needs an object to read, and a missing argument is undefined. With no object, quote(180) stops with TypeError: Cannot read properties of undefined (reading 'rate'). So give the whole parameter a default:
function quote(
words,
{ rate = 0.12, rush = false, minimum = 40 } = {},
) {
const fee = Math.max(words * rate, minimum);
const days = 2 + Math.floor(words / 2000);
if (rush) {
return [fee * 1.5, Math.max(1, Math.floor(days / 2))];
}
return [fee, days];
}
console.log(quote(180));
console.log(quote(6200, { rush: true }));
The café gets its minimum fee, and Bauer Legal keeps its rush quote:
[ 40, 2 ]
[ 1116, 2 ]