title: Group by array of objects by a nested key
body: <p>I have the following data:  </p>
  
  <pre><code>const data = [
      {
          parent: {
              id: "1",
              name: "Europe"
          },
          item: {
              name: "Italy"
          },
          score: 5
      },
      {
          parent: {
              id: "1",
              name: "Europe"
          },
          item: {
              name: "France"
          },
          score: 4.5
      },
      {
          parent: {
              id: "1",
              name: "Europe"
          },
          item: {
              name: "UK"
          },
          score: 4.9
      },
      {
          parent: {
              id: "2",
              name: "Afrique"
          },
          item: {
              name: "Morocco"
          },
          score: 3.1
      },
      {
          parent: {
              id: "2",
              name: "Afrique"
          },
          item: {
              name: "Egypt"
          },
          score: 3.9
      }
  ];
  </code></pre>
  
  <p>I want to group it based on the <code>parent.id</code> and calculate the average score, so I can have the following result:  </p>
  
  <pre><code>[
      {
          parent: {
              id: "1",
              name: "Europe",
              items: [
                  {
                      name: "Italy"
                  },
                  {
                      name: "France"
                  },
                  {
                      name: "UK"
                  }
              ],
              score: 4.8
          }
      },
      {
          parent: {
              id: "2",
              name: "Afrique",
              items: [
                  {
                      name: "Morocco"
                  },
                  {
                      name: "Egypt"
                  }
              ],
              score: 3.5
          }
      }
  ]
  </code></pre>
  
  <p>I used the following function, but it doesn't work for the nested key, and also it's doesn't return the desired result schema.  </p>
  
  <pre><code>let group = cars.reduce((r, a) =&gt; {
     console.log("a", a);
     console.log('r', r);
     r[a.make] = [...r[a.parent.id] || [], a];
     return r;
  }, {});
  console.log("group", group);
  </code></pre>