title: count duplicate values in array using angularjs
body: <p>I have a form with 5 questions and 3 different answers for each question.</p>
  
  <p>e.g. 
  q1. whats is your favorite color?</p>
  
  <p>radio button-1. value blue
  radio button-2. value red
  radio button-3. value grey</p>
  
  <p>most of these questions have the same value (blue, red, grey), which is what I want, however, I'm trying to add all the values together at the end of the form so I can determine if the person filling out the form equals one of the values (blue, red, or grey).</p>
  
  <p>I'm building this form with angularjs and this is what i have so far.</p>
  
  <pre><code> &lt;label&gt;Q1. what is your favorite color?&lt;/label&gt;
      &lt;div class="form-group"&gt;
          &lt;div class="radio"&gt;
              &lt;label&gt;
            &lt;input type="radio" ng-model="formData.color" value="blue"&gt;
                blue
              &lt;/label&gt;
          &lt;/div&gt;
          &lt;div class="radio"&gt;
              &lt;label&gt;
             &lt;input type="radio" ng-model="formData.color" value="red"&gt;
                  red
              &lt;/label&gt;
          &lt;/div&gt;
          &lt;div class="radio"&gt;
              &lt;label&gt;
            &lt;input type="radio" ng-model="formData.color" value="grey"&gt;
                 grey
              &lt;/label&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>this bit of code only works if I have the values already entered into the variable</p>
  
  <pre><code>$scope.formData = { };
  $scope.formData = [];
  $scope.formData.sort();
  var current = null;
  var cnt = 0;
  for (var i = 0; i &lt; $scope.formData.length; i++) {
      if ($scope.formData[i] != current) {
          if (cnt &gt; 0) {
              console.log(current + ' shows ' + cnt + ' times');
          }
          current = $scope.formData[i];
          cnt = 1;
      } else {
          cnt++;
      }
  }
  if (cnt &gt; 0) {
     console.log(current + ' shows ' + cnt + ' times');
  }
  </code></pre>