Sort Array of objects to nested array of objects [closed]

First I am initializing a filterArray which will filter those object which have reporting
manager key and they have not the key value of subordinates. Then Declaring an empty array
of companyHirarchy1.looping through both array and using a condition I am assigning a child variable and then calling another function (parentChild) .

var arr = [
    { position: 'CEO' },
    { position: 'COO', reportingManager: 'CEO' },
    { position: 'CFO', reportingManager: 'COO' },
    { position: 'Finance Manager', reportingManager: 'CFO' },
    { position: 'Accountant', reportingManager: 'Finance Manager' },
    { position: 'Bookkeeper', reportingManager: 'Finance Manager' },
    { position: 'Treasurer', reportingManager: 'CFO' },
  ]

I want to show the given array like:

var resultArray = [
     {
         position: "CEO",
         subordinates: [
             {
                 position: "COO",
                 subordinates: [
                     {
                         position: "CFO",
                         subordinates: [
                             {
                                 position: "Finance Manager",
                                 subordinates: [
                                     {
                                     position: "Accountant",
                                     subordinates: []
                                     },
                                     {
                                         position: "Bookkeeper",
                                         subordinates: []
                                     }
                                 ]
                             },
                             {
                                 position: "Treasurer",
                                 subordinates: []
                             }
                         ]
                     },
                   ]
             },
           ]
    },
   ]

Hope so you will understand my question

I tried this but it just throughs the object inside the subordinate of CEO. What I am missing ?

My practice on this problem.
Result of my practice