我有以下带有递归函数的代码,我想将其转换为递归箭头函数:
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;
});
知道如何做吗?
最佳答案
您可以使用自己的函数进行回调并缩短返回值的条件。
const
check = x => x.link === route.routeConfig.path || x.sections && x.sections.some(check),
hasAccess = menuSections.some(check);
关于javascript - 将递归函数转换为递归箭头函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52643030/