title: Map Two Multi-dimensional Arrays into an Object
body: <p>I was asked in an interview to process two multidimensional arrays into one object with the format similar to:</p>
  <pre><code>{
     'sally': {
         id: 1,
         metrics: {
             sales: 6000,
             missed: 0
         }
     },
     'bob': {
         id: 2,
         metrics: {
             sales: 1000,
             missed: 0
         }
     },..
  }
  </code></pre>
  <p>However, I was unable to figure it out. I've tried doing nested for-loops, but the problem with this is I'm worried about execution time. According to the interviewer, it should have an execution time of <code>O(n)</code> and if I understand Big O correctly, a nested for-loop would have an execution time of around <code>O(n^2)</code>. Here is the code I have so far:</p>
  <pre><code>// returns a dictionary
  let testIAteShitOn = (requested_user = false, requested_metric = false) =&gt; {
    // is the array always organized the same?
    let users = [
      [1, &quot;Sally&quot;],
      [2, &quot;Bob&quot;],
      [3, &quot;George&quot;],
    ];
  
    // same here, is this always organized the same?
    //  are there only ever 2 metrics?
    let metrics = [
      [1, &quot;sales&quot;, 5000],
      [1, &quot;sales&quot;, 1000],
      [3, &quot;missed&quot;, 1000],
      [2, &quot;sales&quot;, 1000],
    ];
  
   for (let i = users.length - 1; i &gt;= 0; i--) {
      let id = users[i][0];
      let data = findDiamond(id, metrics);
  
   }
  
   return obj;
  
  }
  
  
  let findDiamond = (id, array) =&gt; {
      return array.filter((item) =&gt; item[0] == id);
  }
  </code></pre>
  <p>I would appreciate any help on this and advice on where and how to best learn algorithms, data structures, and Big O.</p>