本文介绍了javascript反向字符串算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在解决如何反转字符串.我已经想出了如何反转数组,所以我试图在这个答案中使用该答案.我想我可以将字符串转换为数组,然后从那里开始……这是我目前所拥有的,欢迎提供提示或建议.
I'm tying to solve how to reverse a string. I already figured out how to reverse an array so i'm trying to use that answer in this one. I figure I can convert the string to an array an then just go from there...Well this is what I have so far and tips or advice is welcome.
function reverse(string){
var x = string.split(' ');
for(i=0; i=x.length; i++){
var y= x.pop();
console.log(y);
}
}
推荐答案
查看小提琴:https://jsfiddle.net/1wknqn2d/1/
function reverse(string){
return string.split('').reverse().join('');
}
这篇关于javascript反向字符串算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!