翻转字符串算法挑战

先把字符串转化成数组,再借助数组的reverse方法翻转数组顺序,然后把数组转化成字符串。

function reverseString(str) {
    //使用spilt()数组化
var stringSplit = str.split("");
    //用reverse()反转
    stringReverse= stringSplit.reverse();
    //使用join()连接
    stringJoin = stringReverse.join("");
return stringJoin;
}

reverseString("hello");
    //输出为"olleh"

猜你喜欢

转载自blog.csdn.net/weixin_36790610/article/details/80595707