```ts
/**
 * Folds a list onto itself by adding the first entry to the last, the second to the second-last, and so on.
 */
export function foldEnds(values: number[]): number[]
{
  if (!Array.isArray(values)) {
    throw new Error("Input must be an array");
  }

  const n = values.length;
  const result = new Array(n);
  const mid = Math.floor(n / 2);

  for (let i = 0; i <= mid; i++) {
    const opposite = n - 1 - i;
    if (i === opposite) {
      result[i] = values[i];
    } else {
      result[i] = values[i] + values[opposite];
    }
  }

  return result;
}
```