title: Convert array of objects with parent / child relationships to array of nested objects
body: <p>I have a problem transforming an array of objects to another array of nested objects. How can I transform <code>table</code> to look like <code>transformedTable</code> in the example code below?</p>
  
  <p>Input data:</p>
  
  <pre><code>const table = [
    {id: 1, isMain: null, parentId: null, name:"john"},
    {id: 2, isMain: true, parentId: null, name:"sam"},
    {id: 3, isMain: null, parentId: 2, name:"samantha"},
    {id: 4, isMain: true, parentId: null, name:"kate"},
    {id: 5, isMain: true, parentId: 4, name:"jonathan"},
    {id: 6, isMain: null, parentId: 4, name:"walter"},
    {id: 7, isMain: null, parentId: 5, name:"clara"}
  ]
  </code></pre>
  
  <p>I want to transform the data above to something like this:</p>
  
  <pre><code>transformedTable = [{
      id: 1,
      isMain: null,
      parentId: null,
      name: "john"
    },
    {
      id: 2,
      isMain: true,
      parentId: null,
      name: "sam",
      kids: [{
        id: 3,
        isMain: null,
        parentId: 2,
        name: "samantha"
      }]
    },
    {
      id: 4,
      isMain: true,
      parentId: null,
      name: "kate",
      kids: [{
          id: 5,
          isMain: true,
          parentId: 4,
          name: "jonathan",
          kids: [{
            id: 7,
            isMain: null,
            parentId: 5,
            name: "clara"
          }]
        },
        {
          id: 6,
          isMain: null,
          parentId: 4,
          name: "walter"
        },
      ]
    },
  ]
  </code></pre>