implemented reverse() method for array