我正在尝试进行 Lambda 挑战,输出是它所要求的,但它仍然不正确?
问题是: “修改函数以将给定字符串转换为数组,其中数组中的每个字符都与字符串中的索引相同,并返回它。”
function convertStringToArray(s) {
var output = Array.from("hello");
return output;
}
/* Do not modify code below this line */
const exampleString = 'hello';
const stringAsArray = convertStringToArray(exampleString);
console.log(stringAsArray, '<-- should be ["h", "e", "l", "l", "o"]');
输出
["h", "e", "l", "l", "o"] <-- should be ["h", "e", "l", "l", "o"]
我完全按照它的要求做了,为什么我卡住了?
最佳答案
您的代码采用 s
的参数 - 它会忽略它。
我高度怀疑 lambda 挑战将不同的值传递给您的函数(仅使用 "hello"
作为示例)并且您的代码失败了,因为它只返回 ["h ", "e", "l", "l", "o"]
即使 s
是 "world"
。
尝试在函数的第一行使用 s
而不是 "hello"
。
关于javascript - 我错过了什么? lambda 挑战,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56589336/