JS One Liner Regex


  • 0
    E
    /**
     * @param {string} str
     * @returns {string}
     */
    const reverseWords = function(str) {
        return str.trim().replace(/[\s]+/g, ' ').split(' ').reverse().join(' ')
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.