reverseArray function