title: reset a variable for a reusable function
body: <p>I have a bit of code that counts how many objects are in the returned json and gives me the total number. </p>
  
  <pre><code>loadCountSetOne = 0;
  $.each(dataSetOne.user.customers, function(key, val) {  
      loads =  Object.keys(val.loads).length;
      loadCountSetOne = loadCountSetOne + loads;
      console.log(loadCountSetOne);
  });
  </code></pre>
  
  <p>This works fine, but since I'll need to count these a bunch of times I thought I'd move it into it's own function and call it when I need it with something like <code>counter(val.loads);</code></p>
  
  <pre><code>count = 0;  
  function counter(itemToCount) {
      result =  Object.keys(itemToCount).length;
      count = count + result;
      console.log(itemToCount, result, count);
      return count;
  }
  </code></pre>
  
  <p>When I call the function the 1st time I get the right result. When I call it again it adds the 2nd result to the 1st and so on.</p>
  
  <p>My understanding is that that is what it's supposed to do, but not what I need it to do. I tried resetting the value for <code>count</code> is various places but it didn't work. </p>
  
  <p>Is there a way to make this function give me a result based on the number of objects in <code>itemToCount</code> each time it's called?</p>
  
  <p>Thanks.</p>