Skip to content

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

Description

@biubiukam

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, []);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions