Read rate of change of signal

i am new to this Arduino environment, i am not able to apply the program what Mr, Mark T posted. I want to store the pulses of particular period from sensor and i want to retrieve the maximum and minimum values from that, i ll find the difference of those values and proceed with my decision making using "If" statement. so suggest me the program to store the "duration" in my program attached below and retrieve the max and min duration value.

#define LED_PIN 13
#include <ZumoMotors.h>
const int trigPin = 2;
const int echoPin = 4;
int  duration = 0;        
int  durationMin =  1023;        
int  durationMax = 0;
int aproach = 0;
const int threshold1 = 5;
ZumoMotors motors;
void setup()
{
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
}
void loop()
{
  long duration, inches, cm;
  pinMode (trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
  
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);

Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
while (millis() < 1000) {
  duration = pulseIn(echoPin, HIGH);
     // record the maximum sensor value
    if ( duration >  durationMax) {
      durationMax = duration;
    }

    // record the minimum sensor value
    if ( duration < durationMin) {
       durationMin =  duration;
    }
}
aproach =  durationMax -  durationMin;
 Serial.print(duration);
  Serial.print("du, ");
Serial.print(aproach);
Serial.print("ap, ");
Serial.print(durationMin);
Serial.print("min, ");
Serial.print(durationMax);
Serial.print("max, ");
delay(100);
if (aproach > threshold1)
  {
  motors.setSpeeds(0, 200);
}
else {
   motors.setSpeeds(0, 0);
}
}

long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}