```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 array of numbers to fold.
 * @returns An array containing the folded totals.
 */
export function foldEnds(values: number[]): number[] {
  if (values.length === 0) return [];
  const mid = Math.floor(values.length / 2);
  return values.slice(0, mid).map((value, index) => value + values[values.length - 1 - index]).concat(mid % 2 ? [values[mid]] : []);
}
```