数组连接功能不起作用 [英] array join function not working
本文介绍了数组连接功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于某种原因,我无法看到为什么我的数组连接方法不起作用.这是进行审核的快速代码:
for some reason Im not able to see why my array join method wont work. here's the quick code for review:
function rot13(str) { // LBH QVQ VG!
var strAry = str.split('');
var transformed = strAry.map(function(val){
if(val === " ") return " ";
else{
var code = val.charCodeAt(0);
return String.fromCharCode(code-13);
}
});
transformed.join('');
console.log(transformed);
return transformed;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
这个想法是传递字符串,它将被转换为可读的代码字符串,但是联接不起作用.另外,一些数字不能正确转换,不确定为什么要为那个数字加分.
The idea is to pass in the string and it will be converted to a readable code string, but the join is not working. Also, a few of the digits are not converting properly not sure why, bonus points for that one.
推荐答案
您不保存.join()
transformed = transformed.join('');
或
return transformed.join('');
这篇关于数组连接功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文