New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2014年11月13日 #1
Comments
代码可以使用三个 |
|
不需要创建新对象的哦,想想之前虫哥提到的,利用原生的Array.prototype.reverse方法 |
String.prototype.reverse = function(){ |
String.prototype.reverse = function(){
return Array.prototype.reverse.call(this.split('')).join('');
}; |
String.prototype.reverse = function () {
return this.split('').reverse().join('');
}
console.log('123'.reverse() === '321'); |
String.prototype.reverse = function(){ |
|
String.prototype.reverse=function(){return this.split('').reverse().join('')} |
String.prototype.reverse = function() {
var newStr = '', i = this.length;
for(; i >= 0; i--) {
newStr += this.charAt(i);
}
return newStr;
} |
The text was updated successfully, but these errors were encountered: