perfect reverseArray function