```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 to fold.
 * @returns An array containing the folded totals.
 */
export function foldEnds(values: number[]): number[] {
  if (!values || !Array.isArray(values)) {
    throw new Error("Input must be an array");
  }

  const length = values.length;
  const result: number[] = [];

  for (let i = 0; i < Math.floor(length / 2); i++) {
    result.push(values[i] + values[length - i - 1]);
  }

  if (length % 2 !== 0) {
    result.push(values[length / 2]);
  }

  return result;
}
```