type Trial = { id: string; endsOn: number };
function selectDue(trials: Trial[], today: number, window: number): Trial[] {
return trials.filter(trial => {
const daysLeft = trial.endsOn - today;
return daysLeft >= 0 && daysLeft <= window;
});
}
Selection is another calculation from values. The caller supplies a day and window; the function selects into a new collection, preserving order. TypeScript’s new array still refers to the original trial objects; the contract does not promise a deep copy. Go appends value copies of these simple structs, whose fields are only a string and an integer. Rust clones the small records from a shared slice. Each implementation leaves the supplied records unchanged.