How to reverse this?

So for my game I’m making a system to move platforms around, basically I have an array of way points that it moves to, but now I need it to when it gets to the end it goes in reverse(so like 123454321 and then start again) in an endless loop? but I have no idea on how I might do this >.<

#pragma strict
var transformArray : Transform [];
var speed : float = 10.0;
private var speed2 : float = 0.0;
private var index : int = 0;
private var i:float = 0.0;
private var rate:float = 0.0;
private var dist : float = 0.0;

function Start()
{
Initiate();
}
function Update () 
{ 
    MoveObject(this.transform, transformArray[index], transformArray[index +1], speed2);
}

function MoveObject (thisTransform : Transform, startPos : Transform, endPos : Transform, time : float) 
{
    rate = 1.0/time;
    if (i < 1.0)
    {
        i += Time.deltaTime * rate;
        thisTransform.position = Vector3.Lerp(startPos.position, endPos.position, i);
    }
    else if(index < transformArray.Length-2) 
    {
     index +=1;
     i = 0.0;
     Initiate();
    }
}

function Initiate()
{
  dist = Vector3.Distance(transformArray[index].position, transformArray[index +1].position);
  speed2 = dist * speed;
  Debug.Log ("" + speed2);
}

If I understand you correctly, you just need to store start and end waypoints, then just use Mathf.PingPong to calculate the effective index of the new waypoint.