Solved infinite loop issue when reversing a string or an array.