Complete reverseArray function - refactor