```ts
export function foldEnds(values: number[]): number[] {
  if (values.length === 0) return [];

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

  // If the length is odd, include the middle element as its own total
  if (values.length % 2 !== 0) {
    result.push(values[Math.floor(values.length / 2)]);
  }

  return result;
}
```