Easy Javascript solution


  • 2
    F
    var reverseWords = function(s) {
        var str = s.split(" ");
        for(let i = 0;i < str.length;i++){
            str[i] = str[i].split("").reverse().join("");
        }
        return str.join(" ");
    };
    

  • 0
    T

    @Fitzzzzzz I wrote kinda the same solution but with map instead of for:

    var reverseWords = function(s) {
        return s.split(' ').map((word) => word.split('').reverse().join('')).join(' ')
    };
    

Log in to reply
 

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