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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.