function myTrim(str) {//记录前后空格的个数,最后对字符串进行截取
let first = 0, last = str.length
for (let i in str) {
if (str[i] === ' ') {
first++
} else {
break
};
};
for (let i = last; i > first; i--) {
if (str[i] === ' ') {
last--
} else {
break
};
};
return str.substr(first, last - first)
}
网友评论