1.逆转字符串
var reverseWords = function(s) {
s = s.trim();
let arr = [];
arr = s.split(" ");
arr = arr.reverse();
let str = "";
for(let i=0; i < arr.length; i ++) {
if(arr[i]) {
if(i!==arr.length-1) {
str = str + arr[i] + " ";
} else {
str = str + arr[i];
}
}
}
return str;
};
2.旋转字符串
var reverseLeftWords = function(s, n) {
let left = s.slice(0, n);
let right = s.slice(n,s.length);
return right+left;
};