我正在研究简单的js函数.. 我写了我的代码,但它显示我失败了...... 我正在实现的任务如下......
实现一个函数,该函数将函数作为其第一个参数,数字num作为其第二个参数,然后执行传入的函数num次。 使用下面给出的样板代码开始。大多数/所有未来的练习都将提供样板。
你能告诉我我做错了吗
function operation() {
console.log("testing");
}
function repeat(operation, num) {
// SOLUTION GOES HERE
for (var i = 0; i < num; i++) {
console.log(i);
// more statements
}
}
// Do not remove the line below
module.exports = repeat
错误
验证&#34;高阶函数&#34; ...
ACTUAL EXPECTED
------ --------
"0" != "Called function 1 times."
"" ""
# FAIL
答案 0 :(得分:1)
你跑:
function operation() {
console.log("testing");
}
function repeat(operation, num) {
// SOLUTION GOES HERE
for (var i = 0; i < num; i++) {
console.log(i);
// more statements
}
}
// Do not remove the line below
module.exports = repeat
你期待:
ACTUAL EXPECTED
------ --------
"0" != "Called function 1 times."
"" ""
# FAIL
您正在打印“0”,但您的测试用例需要“被调用的函数x次”。 (第一种情况似乎是1)。
这是因为:
operation()
。operation()
不会将迭代索引作为参数,它应该(它应该以{{1}}的形式接收)。operation(i)
不打印您期望的字符串。修改:当前问题存在许多问题:
operation()
,angular
和jquery
此处不是相关标记。