JavaScript one-liner


  • 0
    P

    New lines added for legibility.

    var reverseWords = function(str) {
        return str
            .split(' ')
            .reduce((a, v) => (v.length ? a.push(v) : null, a), [])
            .reverse()
            .join(' ');
    };
    

Log in to reply
 

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