```ts
export function foldEnds(values: number[]): number[] {
  const result: number[] = [];
  const n = values.length;
  for (let i = 0; i <= n / 2; i++) {
    const left = values[i];
    const right = values[n - 1 - i];
    if (i === n - 1 - i) {
      result.push(left);
    } else {
      result.push(left + right);
    }
  }
  return result;
}
```

This implementation:
- Handles empty arrays (loop doesn't execute, returns `[]`)
- Handles single-element arrays (middle element is its own total)
- Handles even-length arrays by pairing first with last, second with second-last, etc.
- Handles odd-length arrays by returning the middle element as its own total
- Uses `<= n / 2` to correctly include the middle element when `n` is odd (e.g., `n=3` → `i=0,1`; `i=1` is the middle)
- Uses `const` by default, no mutation of input