javascript - 我错过了什么?拉姆达挑战
问题描述
我正在尝试进行 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"
作示例)并且您的代码失败了,因为它只有在is["h", "e", "l", "l", "o"]
时才会返回。s
"world"
尝试在函数的第一行使用s
而不是。"hello"
推荐阅读
- c - 从文件中读取数据时无法为字符串赋值
- python - Rpy2(使用数据框) - 如何解决 Python(NaN) 和 R(NA) 冲突?
- asp.net - 如何在 asp.net core 3.0 中正确实施 PayPal 支付
- python - 如何在 matplotlib 和 seaborn 的不同图表中为相同的索引设置相同的颜色
- php - PHP:如何为集合制作一个包装器,每次我调用它时都会返回集合的下一个元素
- xmlhttprequest - 如何让 Axios 使用 Fetch 而不是 XMLHttpRequest
- postgresql - 如何解决 Postgres 11 错误:无法将插入的元组路由到外部表
- java - 作为 SAML IDP 代理的 Keycloak 有没有办法在不设置映射器的情况下将所有角色传递给客户端?
- xml - 使用 Xquery 将不同的值聚合到 xml
- mongodb - 两个集合上的匹配查询