<think>
Okay, I need to implement the fold_ends function. The task says to fold a list onto itself by adding the first entry to the last, the second to the second-last, and so on. The result should be the totals in that order. If the list has an odd length, the middle element is its own total.

First, I need to understand how the folding works. For example, if the input is [1, 2, 3, 4, 5], then the first and last elements (1 and 5) are added, then second and fourth (2 and 4), and the middle element 3 is left as is. So the output would be [6, 6, 3].

Wait, but the problem says "the totals in that order". So the order is first pair, then second pair, etc. For even-length lists, all elements are paired. For odd-length, the middle is left as a single total.

So the steps are:

1. Iterate from the start and end towards the center.
2. For each step, take the element from the start and the corresponding element from the end.
3. Sum them and add to the result list.
4. If the list has an odd length, the middle element is added as a single element in the result.

But how to handle the indices? Let's think about the indices. For a list of length n:

- If n is even, the number of pairs is n/2. Each pair is (i, n-1 -i) for i in 0 to (n/2 -1).
- If n is odd, the number of pairs is (n-1)/2, and the middle element is at index (n//2).

So, for each i in 0 to (len(values) // 2 - 1), we take values[i] + values[-(i+1)].

Wait, let's test with the example [1,2,3,4,5]. The length is 5, so middle is at 2. The pairs are (0,4), (1,3). Then the middle is 2. So the result is [1+5, 2+4, 3] → [6,6,3].

Another example: [1,2,3,4]. The pairs are (0,3), (1,2). So [1+4, 2+3] → [5,5].

So the approach is:

- For each i from 0 to (len(values) // 2 - 1), compute the sum of values[i] and values[-(i+1)].

But wait, for i in 0 to (len(values) // 2 - 1), because for even length, len(values) // 2 is n/2. For example, len 4: 4//2 is 2. So i ranges from 0 to 1 (since 2-1=1). So for i=0, take 0 and 3. For i=1, take 1 and 2.

Yes. So the loop would run for i in range(0, len(values) // 2).

But wait, len(values) // 2 for even n is n/2. So for i in 0 to (n//2 - 1). So the loop is for i in range(len(values) // 2).

Wait, for example, len 4: len//2 is 2. So range(2) is 0,1. Which is correct.

For len 5: len//2 is 2. So range(2) is 0