Simple string reverser in JavaScript