title: Swap two array elements in a functional way
body: <p>I'm trying to swap 2 elements within an array in a functional way in javascript (es6)</p>
  
  <pre><code>let arr = [1,2,3,4,5,6]
  let result = swap(arr, 1, 2) // input: array, first element, second element
  // result=[1,3,2,4,5,6]
  </code></pre>
  
  <p>The only way I could think about is:</p>
  
  <pre><code>const swap = (arr, a, b) =&gt; 
              arr.map( (curr,i) =&gt; i === a ? arr[b] : curr )
                 .map( (curr,i) =&gt; i === b ? arr[a] : curr )
  </code></pre>
  
  <p>But this code runs twice over the array, and not readable at all.
  Any suggestions for a nice clean functional code?</p>
  
  <p>Thanks.</p>