# 美团面试题

// 实现一个深拷贝
const obj = {
  a: [1, 2, null],
  b: {
    c: 2,
    d: function() {},
    e: undefined,
  },
  e: null,
  f: () => {
    console.log("hello");
  },
  g: undefined,
};

// 打平的数组转成树形数组

const arr = [
  { id: 1, parentId: null },
  { id: 3, parentId: 2 },
  { id: 2, parentId: 1 },
  { id: 5, parentId: 3 },
  { id: 6, parentId: 3 },
];

const arr1 = [
  {
    id: 1,
    children: [
      {
        id: 2,
        children: [
          {
            id: 3,
            children: [{ id: 5 }, { id: 6 }],
          },
        ],
      },
    ],
  },
];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Last Updated: 6/27/2023, 7:40:45 PM