title: Find highest average in JavaScript 2d array of students scores
body: <p>Yesterday, I faced this interview question. Initially, it seemed pretty easy, at least logically. 
  But somehow, I could not make it work in JavaScript.</p>
  
  <p><strong>Here is a 2d array of student scores, student names might be repeated multiple times. If this is the case, sum up all the scores and divide by the number of occurrences to find the average, do the Math.floor if necessary.</strong></p>
  
  <pre><code>var arr = [
      ["Bobby","87"],
      ["Charles","100"],
      ["Eric","65"],
      ["Charles","22"],
      ["Charles","37"],
      ["Eric","49"]]
  </code></pre>
  
  <p>So, <code>Charles</code> average score would be <code>Math.floor((100+22+37)/3) = 53</code>
  And, for <code>Eric</code> it would be <code>Math.floor((65+49)/2) = 57</code>.</p>
  
  <p>So highest average would be <code>["Bobby","87"]</code>.</p>
  
  <p>So far what I have tried fruitlessly..</p>
  
  <pre><code>var op_arr = [];
  arr.each(function(item) {
      var sum = 0;
      var itemCount = 1;
      var checkFlag = isItemInArray(arr,item);
      if(checkFlag) {
          itemCount++;
          sum += item[1];
      }
  });
  function isItemInArray(array,item) {
      for(let i = 0;i &lt; array.length; i++) {
          if(array[i][0] === item[0]) {
              return array[i];
          }
      }
      return false;
  }
  </code></pre>
  
  <p>But this does not work.
  Please help me and explain the logic.</p>