Function for reversing an array