title: Functional way to get previous element during map
body: <p>I have an array which I <code>map</code> over. I need to compare the current element with the previous. I am detecting if the current element is the same as the previous element by comparing their <code>id</code>s and doing something different based on this condition. Is there any purely functional way to do it without doing index math? </p>
  
  <pre><code>items.map((item, index) =&gt; {
      if(item.id === items[index - 1 &gt; 0 ? index - 1 : 0].id) {
      // do something
  } else {
     // do something else
   }
  })
  </code></pre>
  
  <p>The code works but I would like to avoid doing math on the index. Is there any way to do it?</p>