简体   繁体   English

将递归函数转换为递归箭头函数

[英]Transform recursive function to recursive arrow function

I have the following code with a recursive function which I would like to transform to recursive arrow function: 我有以下带有递归函数的代码,我想将其转换为递归箭头函数:

const hasAccess = menuSections.some(function s(x) {
  if (x.link === route.routeConfig.path) {
    return true;
  }

  if (x.sections) {
    return (x.sections.some(s));
  }

  return false;
});

Any idea on how to do it? 有什么想法吗?

You could use an own function for callback and shorten the conditions for the return value. 您可以使用自己的函数进行回调,并缩短返回值的条件。

const 
    check = x => x.link === route.routeConfig.path || x.sections && x.sections.some(check),
    hasAccess = menuSections.some(check);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM