Writing an analog pot debounce as a function

Went over to StackOverflow and found a good explanation on how to do things better.

Sharing here for people who run by this thread.

   struct Pot {
   byte pin;
   int threshold;
   int lastReading;
   int currentReading;
  };
    
  struct Pot pots[] = { {A0, 2},{A2,2},{A4,2} }; 

  void rePot(struct Pot * pot) { 
    int reading = map(analogRead(pot->pin), 0, 665, 0, 200);
    
    if(abs(reading - pot->lastReading) >= pot->threshold){
      pot->currentReading = (reading/2);
      Serial.println(pot->currentReading);
      pot->lastReading = reading;
    }  // end of if statement
  
  } // end of rePot

void setup(){
    Serial.begin(9600);
  }
  
  void loop(){
    rePot(&pots[0]);
    rePot(&pots[1]);
    rePot(&pots[2]);
    delay(10);
  }