Complete reverseArray function