Article directory
replace spaces
topic
the code
var replaceSpace = function(s) {
return s.replace(/ /g, "%20");
};
var replaceSpace = function(s) {
return s.split(' ').join('%20');
};
left rotate string
topic
train of thought
- First repeat the string once, splicing at the end
- calculate
n = k % len
- Then
n
intercept from the double string,len
just intercept
the code
var reverseLeftWords = function(s, n) {
let len=s.length;
let num=n%len;
let str=`${
s}${
s}`
return str.slice(num,num+len)
};