There is no single, definite answer to your question.
We can say that the counter is a variable that increases every time this event is checked (for example, when repeating the array every time you encounter the number 5, you can increase the counter by 1).
The concept can be generalized, because at each step there are counters that increase by 2, 3 or any value; however, counter semantics usually lose their meaning if the step is not always the same. It depends on the logic of your program, in the end: if you track single and double rooms in a hotel, your numGuests counter may increase in increments of 1 and 2 depending on the numbers you are processing at the moment, however, it can be argued that in the end itβs easy for clarity or brevity, because the result is the same as incrementing it by 1 , twice!
The battery, instead, is a variable that, for example, stores the sum of the elements of the array (i.e. you do not have a fixed step, but the increment changes depending on the elements you encounter).
The designation can be generalized to a list of elements by repeatedly applying the given function f to the actual value of the accumulator and the next element of the list, storing the result in our accumulator. Thus, we got the semantics of the fold high-order function (in fact, one of its other names is accumulating). If we limit our analysis to what is called the left fold, the accumulator at each moment maintains an intermediate result that is valid for the already processed subset.
If you have a drive with the name total with a starting value of 0 and an array that contains sales for 12 months of the year, using this definition with + (addition) as our f , you will receive at the nth step sales for the first n months of the year.
Your examples look good, as they strictly adhere to these definitions of batteries and counters.