摘记: 1. ```javascript var reverse = function( str ){ var newStr = '', i = str.length; for(; i >= 0; i--) { newStr += str.charAt(i); } return newStr; }; reverse('abcde') ``` ..

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('');
};
原文地址: https://www.cnblogs.com/bbcfive/archive/2018/11/29/10041420.html