title: Move in doubly linked list Ramda.js
body: <p>When I started using a doubly linked list, it became more difficult to manage <code>prev_id</code> &amp; <code>next_id</code>.</p>
  
  <pre><code>const dll = [
    {id: '14', prev_id: null, next_id: '41'}, // &lt;- source
    {id: '41', prev_id: '14', next_id: '22'}, 
    {id: '22', prev_id: '41', next_id: '45'},
    {id: '45', prev_id: '22', next_id: null}, // &lt;- destination
  ]
  </code></pre>
  
  <p>For example, I want to move object <code>14</code> to the end, so the array should become:</p>
  
  <pre><code>const dll_result = [
    {id: '41', prev_id: null, next_id: '22'}, 
    {id: '22', prev_id: '41', next_id: '45'},
    {id: '45', prev_id: '22', next_id: '14'},
    {id: '14', prev_id: '45', next_id: null},
  ]
  </code></pre>
  
  <p>The hardest thing what I need to do to change the <code>prev_id</code> &amp; <code>next_id</code> of the objects?</p>
  
  <p>My attempt:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.as-console-wrapper { max-height: 100% !important; top: 0; }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script type="text/javascript" charset="utf8" src="//cdn.jsdelivr.net/npm/ramda@0.27.0/dist/ramda.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
    const {move} = R
  
    const dll = [
      {id: '14', prev_id: null, next_id: '41'}, //&lt;- source
      {id: '41', prev_id: '14', next_id: '22'}, //&lt;- destination
      {id: '22', prev_id: '41', next_id: '45'}, 
      {id: '45', prev_id: '22', next_id: null}, 
    ]
  
    const fromId = '14'
    const toId = '41' 
  
    const fromItem = dll.find(item =&gt; item.id === fromId)
    const toItem = dll.find(item =&gt; item.id === toId)
  
    const updated = dll.map(item =&gt; {
      if (item.id === fromId) {
        return {...item, prev_id: toId, next_id: toItem.next_id}
      } else if (item.prev_id === fromId) {
        return {...item, prev_id: fromItem.prev_id}
      } else if (item.id === toItem.next_id) {
        return {...item, prev_id: fromId} 
      } else if (item.id === toId) {
        return {...item, next_id: fromId}    
      } else {
        return item
      }
    })
  
    console.log(JSON.stringify(move(0, 1, updated), null, 2))
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>