title: Transform data other way around (groups of items instead of items with group references)
body: <p>How do i make a function that can transform data of type <code>DevicesType</code> to <code>GroupsType</code> bellow?
  So instead of getting list of devices saying what groups they are in I need a list of groups containing their respective devices.</p>
  <pre><code>type DevicesType = {
    id: string
    name: string
    status: &quot;OK&quot; | &quot;FAULTY&quot;
    groups: {
      id: string
      name: string
    }[]
  }[]
  </code></pre>
  <pre><code>type GroupsType = {
    id: string
    name: string
    devices: {
      id: string
      name: string
      status: &quot;OK&quot; | &quot;FAULTY&quot;
    }[]
  }[]
  </code></pre>
  <p>Example data would be:</p>
  <pre><code>const devicesFromBackend: DevicesType = [
    {
      id: &quot;d1&quot;,
      name: &quot;device 1&quot;,
      status: &quot;OK&quot;,
      groups: [
        {
          id: &quot;g1&quot;,
          name: &quot;group 1&quot;
        },
        {
          id: &quot;g2&quot;,
          name: &quot;group 2&quot;
        }
      ]
    },
    {
      id: &quot;d2&quot;,
      name: &quot;device 2&quot;,
      status: &quot;FAULTY&quot;,
      groups: [
        {
          id: &quot;g2&quot;,
          name: &quot;group 2&quot;
        },
        {
          id: &quot;g3&quot;,
          name: &quot;group 3&quot;
        }
      ]
    }
  ];
  </code></pre>
  <p>I wanna do this to render tables for each group with list of their respective devices.</p>