问题描述
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;
};