Day15. Reverse Words in a String III(557)

问题描述
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example

Input: "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"

为什么完全没考虑转义字符的存在,就a了,,,

/**
 * @param {string} s
 * @return {string}
 */
var reverseWords = function(s) {
    var arr = s.split(' ');
    var Arr = [];
    for(let i = 0; i<arr.length; i++){
        Arr.push(arr[i].split('').reverse().join(''));  
    }
    var str = Arr.join(' ');
    return str;
};
    原文作者:前端伊始
    原文地址: https://www.jianshu.com/p/6f5939bfe618
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞