Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DFS这里是否能调整为尾递归 #454

Open
kampiu opened this issue Jan 9, 2024 · 0 comments
Open

DFS这里是否能调整为尾递归 #454

kampiu opened this issue Jan 9, 2024 · 0 comments

Comments

@kampiu
Copy link

kampiu commented Jan 9, 2024

function dig(list: DefaultOptionType[], keepAll: boolean = false) {

function dig(list: DefaultOptionType[], keepAll: boolean = false): DefaultOptionType[] {
  function digRecursive(list: DefaultOptionType[], result: DefaultOptionType[]): DefaultOptionType[] {
    if (list.length === 0) {
      return result;
    }

    const dataNode = list[0];
    const children = dataNode[fieldChildren];
    const match = keepAll || filterOptionFunc(searchValue, fillLegacyProps(dataNode));
    const childList = dig(children || [], match);

    if (match || childList.length) {
      result.push({
        ...dataNode,
        isLeaf: undefined,
        [fieldChildren]: childList,
      });
    }

    return digRecursive(list.slice(1), result);
  }

  return digRecursive(list, []);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant