Two multi-dimensional array matching

how to match two tree arrays and return the corresponding values, such as

const arr = [
  {
    id: 1,
    name: "a",
    icon: "b",
    children: [
      {
        id: 1-1,
        name: "a-1",
        icon: "b-1",
        children: [
          {
            id: 1-1-1,
            name: "a-1-1",
            icon: "b-1-1",
          },
          {
            id: 1-1-2,
            name: "a-1-2",
            icon: "b-1-2",
          }
        ]
      },
      {
        id: 1-2,
        name: "a-2",
        icon: "b-2",
      }
    ]
  },
  {
    id: 2,
    name: "c",
    icon: "d",
    children: [
      {
        id: 2-1,
        name: "c-1",
        icon: "d-1",
        children: [
          {
            id: 2-1-1,
            name: "c-1-1",
            icon: "d-1-1",
          }
        ]
      }
    ]
  },
  {
    id: 3,
    name: "e",
    icon: "f",
  }
]

const arr2 = [
  {
    id: 1,
    children: [
      {
        id: 1-1,
        children: [
          {
            id: 1-1-1
          }
        ]
      }
    ]
  },
  {
    id: 2,
    children: [
      {
        id: 2-1
      }
    ]
  }
]

return:

[
  {
    id: 1,
    name: "a",
    icon: "b",
    children: [
      {
        id: 1-1,
        name: "a-1",
        icon: "b-1",
        children: [
          {
            id: 1-1-1,
            name: "a-1-1",
            icon: "b-1-1"
          }
        ]
      }
    ]
  },
  {
    id: 2,
    name: "c",
    icon: "d",
    children: [
      {
        id: 2-1,
        name: "c-1",
        icon: "d-1"
      }
    ]
  },
Jun.16,2022

personal thinking goes like this:

  1. Let's first turn json into a tree
  2. then compare whether the two trees are exactly the same

function fn(data, arr) {
 var newArr = [];
 for(var i=0,l=data.length;i<l;iPP){
   if(arr[i]){
     var opt = {};
     opt = Object.assign({},arr[i]);
     opt.children = [];
     newArr.push(opt);    
     if(data[i].children)
       newArr[i].children.push(fn(data[i].children, arr[i].children)); 
   }
  }
  return newArr;
}

fn(arr2,arr); //,
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea2e8d-1c13.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea2e8d-1c13.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?