问题
编写一个函数,获取序列和值,并根据变量是否存在于多维序列中返回真/假。
例子:
locate(['a','b',['c','d',['e']]],'e'); // should return true
locate(['a','b',['c','d',['e']]],'a'); // should return true
locate(['a','b',['c','d',['e']]],'f'); // should return false
我的解决方案似乎可行,但 Code Wars 说:“arr.flat 不是函数。
我使用免费的代码营浏览器来运行和测试我的代码,我的控制台日志表明我已经让它工作了,但是 Code Wars 说 arr.flat 不是一个函数。这是我的代码:
var locate = function(arr, value){
let count = 0;
arr.flat().map((item)=>{
value == item ? count++ : count;
});
return count > 0 ? true : false;
}
我的问题
我的代码是否正确?如果不是,那有什么问题。如果是这样,为什么 Code Wars 会抛出错误?
炎炎设计
慕斯709654
SMILET
慕哥9229398
相关分类