title: Faster way to find an occurrence of 2-Dimensional array of keywords with frequency value
body: <p>Do I have a faster way to count all frequency of all elements in 2-Dimensional array? Like this sample: <br></p>
  
  <pre><code>var array = [["a", "b"]["c", "d"]["b", "d"]["c", "a", "b"], ["a", "b", "c", "d"];
  </code></pre>
  
  <p>My expected result would be an array of objects contain keyword and frequency value. <br>
  Like this,</p>
  
  <pre><code>result = [{ keyword: "a",
              frequency: 3
            }, {
              keyword: "b",
              frequency: 4
            }, ... ];
  </code></pre>
  
  <p>Here is my solution:</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-js lang-js prettyprint-override"><code>function generateData (records) {
    var data = [];
    for (var i = 0; i &lt; records; ++i) {
        data.push(["a", "b", "c", "d", "e"]);
    }
    // some gap to insert data
    setTimeout(function () {
    }, Math.random() * 1000);
    return data;
  }
  
  function mine (data) {
    var result = [];
    data.forEach( function (keywords) {
        for (var i = 0, len = keywords.length; i &lt; len; ++i) {
            var pos = result.map( function (x) {
                return x.keyword;
            }).indexOf(keywords[i]);
  
            if (pos == -1) {
                var newKeyword = {
                    keyword: keywords[i],
                    frequency: 1
                }
                result.push(newKeyword);
            } else { 
                result[pos].frequency += 1;
            }
        }
    });
    return result;
  }
  
  var dataset = generateData(50000);
  
  var start = performance.now();
  var result = mine(dataset);
  var end = performance.now();
  
  console.log(result);
  console.log("Total time: " + (end - start) + " milliseconds.");</code></pre>
  </div>
  </div>
  </p>
  
  <p>Does anyone have a faster way to solve this problem?
  Note: With 2-Dimensional of keywords array (around ~50,000 records).</p>