编写一个高阶函数checkConsistentOutput()


这个函数应该有两个参数:一个函数和一个值。它应该调用具有该值的参数函数两次。如果回调函数两次产生相同的结果,则应返回函数调用的结果,否则,应返回字符串"This function returned consistent results"
const checkThatTwoPlusTwoEqualsFourAMillionTimes = () => {
for(let i = 1; i <= 1000000; i++) {
if ( (2 + 2) != 4) {
console.log('Something has gone very wrong :( ');
}
}
};
const addTwo = num => num + 2;
const timeFuncRuntime = funcParameter => {
let t1 = Date.now();
funcParameter();
let t2 = Date.now();
return t2 - t1;
};
// Write your code below
const time2p2 = timeFuncRuntime(checkThatTwoPlusTwoEqualsFourAMillionTimes);
const checkConsistentOutput(func, val) => {
let checkOne = func(val);
let checkTwo = func(val);
if (checkOne === checkTwo){
return checkOne;
} else {
return 'This function returned inconsisent results'
}
}

我得到错误SyntaxError:const声明中缺少初始值设定项。请帮我理解。

我在最后一个const声明中看到一个错误,似乎是因为它缺少一个'='。

const checkConsistentOutput(func, val) => {
...
}
const checkConsistentOutput = (func, val) => {
...
}

相关内容

  • 没有找到相关文章

最新更新