Implement FirstReverse in JavaScript