Writing an analog pot debounce as a function

Let me take a turn asking questions.

To determine if this potentiometer reading is the same as the last one, how many variables are needed? How many do you have?

If the readings are the same, is the mapping necessary? The other manipulations?

In other words, the function should return the mapped, manipulated value only if the current reading is not the same as the previous reading, and the only values that need to be persisted are the previous reading and the previously returned value.

Return the same value if the readings are the same. Calculate and return a new value if the readings are different.

Use names that appear to be related, like currentReading and previousReading, not j and lastPotVal (or is that prevPotVal?).