title: Ramda - how to groupBy and transform
body: <p>I am trying to group elements by <code>groupId</code> and create a new structure.</p>
  <p>Elements to group (For presentation purposes each group contains only one element but there are multiple groups with multiple elements):</p>
  <pre><code>const nodes = [
      {
          &quot;id&quot;: 163779,
          &quot;groupId&quot;: 0,
          &quot;width&quot;: 400,
          &quot;height&quot;: 368.28125
      },
      {
          &quot;id&quot;: 163783,
          &quot;groupId&quot;: 1,
          &quot;width&quot;: 216.40625,
          &quot;height&quot;: 102.453125
      }
  ]
  </code></pre>
  <p>I tried to use <code>R.groupBy(R.prop('groupId'))(nodes)</code> and that worked fine as a first step as a result I got:</p>
  <pre><code>{
      &quot;0&quot;: [
          {
              groupId: 0,
              height: 368.28125,
              id: 163779,
              width: 400
          }
      ],
      &quot;1&quot;: [
          {
              groupId: 1,
              height: 102.453125,
              id: 163783,
              width: 216.40625
          }
      ]
  }
  </code></pre>
  <p>But I don't know how to achieve such a structure:</p>
  <pre><code>[
    {
      &quot;id&quot;: 0,
      &quot;children&quot;: [
        {
          &quot;id&quot;: 163779,
          &quot;groupId&quot;: 0,
          &quot;height&quot;: 368.28125,
          &quot;width&quot;: 400
        }
      ]
    },
    {
      &quot;id&quot;: 1,
      &quot;children&quot;: [
        {
          &quot;id&quot;: 163783,
          &quot;groupId&quot;: 1,
          &quot;height&quot;: 102.453125,
          &quot;width&quot;: 216.40625
        }
      ]
    }
  ]
  </code></pre>
  <p>Any help would be appreciated. Thank you</p>