标签:字符 js字符串 news cti new nbsp += split tac
1.
var reverse = function( str ){
var newStr = ‘‘, i = str.length;
for(; i >= 0; i--) {
newStr += str.charAt(i);
}
return newStr;
};
reverse(‘abcde‘)
2.
var reverse = function( str ){
return str.split(‘‘).reverse().join(‘‘);
};
3.(类似法2)
var reverse = function( str ){
var stack = [];//生成一个栈
for(var len = str.length,i=len;i>=0;i-- ){
stack.push(str[i]);
}
return stack.join(‘‘);
};
标签:字符 js字符串 news cti new nbsp += split tac
原文地址:https://www.cnblogs.com/bbcfive/p/10041420.html