title: How to add a new entry to an array after a certain property changes?
body: <p>I am trying to add a new entry to an array after a certain property, in my case &quot; place&quot;, changes. However, I have big problems to find a suitable approach, because the operation depends on the next object in the array.</p>
  <pre><code>const initalData = [
    { storyID: 1, place: 12, type: &quot;Story&quot; },
    { storyID: 5, place: 12, type: &quot;Story&quot; },
    { storyID: 99, place: 45, type: &quot;Story&quot; }, 
    { storyID: 8, place: 31, type: &quot;Story&quot; },
    { storyID: 16, place: 31, type: &quot;Story&quot; },
    { storyID: 20, place: 45, type: &quot;Story&quot; },
    { storyID: 22, place: 45, type: &quot;Story&quot; },
  ];
  </code></pre>
  <pre><code>const targetData = [
    { placeID: 12, type: &quot;Place&quot; }, // new added entry based on the next  &quot;place&quot;
    { storyID: 1, place: 12, type: &quot;Story&quot; },
    { storyID: 5, place: 12, type: &quot;Story&quot; },
    { placeID: 45, type: &quot;Place&quot; }, // // new added entry based on the next  &quot;place&quot;
    { storyID: 99, place: 45, type: &quot;Story&quot; },
    { placeID: 31, type: &quot;Place&quot; }, // new added entry based on the next  &quot;place&quot;
    { storyID: 8, place: 31, type: &quot;Story&quot; },
    { storyID: 16, place: 31, type: &quot;Story&quot; },
    { placeID: 45, type: &quot;Place&quot; },// new added entry based on the next  &quot;place&quot;
    { storyID: 20, place: 45, type: &quot;Story&quot; },
    { storyID: 22, place: 45, type: &quot;Story&quot; },
  ];
  </code></pre>
  <p>Currently I have looked at <code>groupBy(&quot;place&quot;)</code> as a possible approach, but the ultimate array structure here is not what I need.</p>