title: Most efficient way to add unique ids to deeply nested array of objects
body: <p>I need to add ids to an array of objects:
  Example:</p>
  
  <pre><code>const workouts = [
    { 
      type: "walk"
      areas: [
        {
          location: 'park'
          day: 'Sunday'
        },
        {
          location: 'beach'
          day: 'Monday'
        }
      ],
      exercise: true
    },
    { 
      type: "run"
      areas: [
        {
          location: 'gym'
          day: 'Saturday'
        },
        {
          location: 'track'
          day: 'Sunday'
        }
      ],
      exercise: true
    }
  ]
  </code></pre>
  
  <p>In this example, I need to add ids to the <code>workouts</code> array and the deeply nested <code>areas</code> array. 
  I came up with this solution mapping through each of the arrays:</p>
  
  <pre><code>const idMappings = workouts.map((workout) =&gt; {
      const workoutIdMapping = workout.id ? workout : { ...workout, id: uuid.v4() }; // if there is already an id just return the object -- otherwise generate a random id
      const areasIdMapping = workoutIdMapping.areas.map((area) =&gt; {
          return area.id ? area : { ...area, id: uuid.v4() }; // if there is already an id just return the object -- otherwise generate a random id
      });
      return { ...workoutIdMapping, areas: areasIdMapping }; // finally return the updated values with ids
  });
  </code></pre>
  
  <p>This correctly returns me the following area with ids:</p>
  
  <pre><code>const workouts = [
    { 
      id: "0000-0000-4e6b-9f24-f8e1f2402a9b"
      type: "walk"
      areas: [
        {
          id: "0000-1111-4e6b-9f24-f8e1f2402a9b"
          location: 'park'
          day: 'Sunday'
        },
        {
          id: "0000-2222-4e6b-9f24-f8e1f2402a9b"
          location: 'beach'
          day: 'Monday'
        }
      ],
      exercise: true
    },
    { 
      id: "1111-0000-4e6b-9f24-f8e1f2402a9b"
      type: "run"
      areas: [
        {
          id: "1111-1111-4e6b-9f24-f8e1f2402a9b"
          location: 'gym'
          day: 'Saturday'
        },
        {
          id: "1111-2222-4e6b-9f24-f8e1f2402a9b"
          location: 'track'
          day: 'Sunday'
        }
      ],
      exercise: true
    }
  ]
  </code></pre>
  
  <p>This algorithm worked correctly but is there a more efficient way to solve this problem -- Is mapping multiple times not an efficient way of approaching this problem -- perhaps there are better ES6 functions I can use?</p>