Giter Site home page Giter Site logo

docs's Introduction

  1. 实现一个函数 pathToTree(pathList:string[])
  2. 调用示例
const pathList = [
  "vitepress",
  "vitepress/gutter",
  "nodejs",
  "nodejs/gutter",
  "nodejs/variable",
  "nodejs/variable/number",
  "nodejs/variable/array",
  "nodejs/variable/tet",
];
const result = pathToTree(pathList);
console.lg(result);

输出如下结果 items 为子节点 其中 link 字段只有 节点有 目录没有 items 只有目录有 子节点不能存在

[
  {
    "text": "/vitepress"
  },
  {
    "text": "/vitepress",
    "items": [
      {
        "text": "gutter",
        "link": "/vitepress/gutter/index"
      }
    ]
  }
]

我期望返回的是

[
  {
    "text": "/vitepress",
    "items": [
      {
        "text": "/vitepress/gutter",
        "link": "/vitepress/gutter/index"
      }
    ]
  }
]

实际返回的是

[
  {
    "text": "/vitepress",
    "link": "/vitepress/index",
    "items": [
      {
        "text": "/vitepress/gutter",
        "link": "/vitepress/gutter/index"
      }
    ]
  }
]
  1. 实现一个对象访问函数 我传入 dir/test/test 第二个参数为需要访问的对象 返回 对象 {dir:{test:test{}}}

convertToTree

  1. 参数
const buffer = {}; // 存储临时变量
const pathList = ["vite", "vite/vitepress"];
// split 之后
const _pathList = [["vite"][("vite", "vitepress")]];
  1. 参数处理,遍历结构 1.1. vite buffer[vite] = {text:"vite"} 2.1. vite buffer[vite] = [] 2.2 vitepress
  2. 期望值返回

期望结构

const equal = [
  {
    text: "vite",
    items: [
      {
        text: "vitepress",
        link: "vite/vitepress",
      },
    ],
  },
];

docs's People

Contributors

alaricweb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.