// --------------------------------------------------------------------------- // Which iteration "Video from an article" (/create, P5) offers first: the // NEWEST done iteration with a report of its OWN -- a chain cuts from a report, // so a video revision that carries an earlier iteration's report is never the // default (it can still be chosen). Plain ESM, unit-tested. // --------------------------------------------------------------------------- /** * The iterations a chain can run over: done, with a report (its own or an * ancestor's), newest first. * @template {{ n: number, status: string, hasReport: boolean, reportFrom: number | null }} T * @param {T[]} iterations * @returns {T[]} */ export function chainable(iterations) { return iterations.filter((it) => it.status === "done" && it.reportFrom !== null).sort((a, b) => b.n - a.n); } /** * The default: the newest done iteration with its own report, else null. * @param {{ n: number, status: string, hasReport: boolean, reportFrom: number | null }[]} iterations * @returns {number | null} */ export function defaultChainIteration(iterations) { return chainable(iterations).find((it) => it.hasReport)?.n ?? null; }