title: abstract javascript code into ES6 function
body: <p>I have some code that is working but I want to abstract it into a functional component I can use elsewhere in my script. I am getting an undefined error:</p>
  
  <p>This works:</p>
  
  <pre><code>//add an index to each element
      var items = learning_check.map(function(el,i) {
        var o = Object.assign({}, el);
        o.key = i;
        return o;
      });
  </code></pre>
  
  <p>this doesn't:</p>
  
  <pre><code>const addIndex = (a) =&gt; {
    console.log('addIndex initiated')
    a.map = (el,i) =&gt; {
      var o = Object.assign({}, el);
      o.key = i;
      return o;
    }
  }
  </code></pre>
  
  <p>called with </p>
  
  <pre><code>const mItems = addIndex(learning_check); // initiated
  console.log('mItems: ' + mItems); // undefined
  </code></pre>