```ts
/**
 * Fold a list onto itself by adding the first entry to the last, the second to the second-last, and so on,
 * returning the totals in that order. A list of an odd length leaves its middle entry as its own total.
 * @param values - The list of numbers to fold.
 * @returns The list of folded totals.
 */
export function foldEnds(values: number[]): number[] {
    if (values.length === 0) return [];
    const result: number[] = [];
    for (let i = 0; i < Math.floor(values.length / 2); i++) {
        result.push(values[i] + values[values.length - 1 - i]);
    }
    if (values.length % 2 !== 0) {
        result.push(values[Math.floor(values.length / 2)]);
    }
    return result;
}
```