为了账号安全,请及时绑定邮箱和手机立即绑定

递归函数不断返回false

递归函数不断返回false

叮当猫咪 2021-08-20 16:47:22
我有一点麻烦,为什么我的递归函数总是返回 false。const location = {   name: "917",   parentLocationCluster: {     name: "Key Zones"      ParentLocationCluster: {        name: "Bla"     }   }}const test = CheckIfInKeyZone(location)const CheckIfInKeyZone = (parentLocationCluster) => {  if(parentLocationCluster.name === 'Key Zones') {    return true;  }  else if(parentLocationCluster.parentLocationCluster) {    const { parentLocationCluster: location } = parentLocationCluster;    CheckIfInKeyZone(location);  }  return false;}; 在parentLocationCluster.name === 'Key Zones' 被击中,在我期待的返回值是真实的,但它不是。帮助?
查看完整描述

3 回答

?
慕容708150

TA贡献1831条经验 获得超4个赞

小错误应该是:

返回 CheckIfInKeyZone(location);


查看完整回答
反对 回复 2021-08-20
  • 3 回答
  • 0 关注
  • 216 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号