I am swapping content based on a loaded in array (so the length of the array will be dynamic each time) and I'm trying to figuire out how to handle the first and last item in this method. As in - I need when you click left from the first one it would go to the last and opposite for the last.

So I just have this -

```
 <div class="side{{side.name}} side" ng-repeat="side in sides" ng-show="side.active" >
            {{side.name}}
            <i class="fa fa-chevron-circle-left" ng-click="flipLeft($index)"></i>
            <i class="fa fa-chevron-circle-right" ng-click="flipRight($index)"></i>
        </div>

```

and in the controller it just looks like this 

```
$scope.flipLeft = function (index){
    $scope.sides[index].active = false;
    $scope.sides[index-1].active = true;

};

$scope.flipRight = function (index){
    $scope.sides[index].active = false;
    $scope.sides[index+1].active = true;

};

```

So all it really does is swap the .active to true or false to show or hide the content. I'm not sure how to switch around my logic so it loops around so that if you click left on the first item it goes to the last and visa versa. Thanks in advance!