title: Remove last comma (and possible whitespaces after the last comma) from the end of a string
body: <p>Using JavaScript, how can I remove the last comma,  but only if the comma is the last character or if there is only white space after the comma? This is my code.
  I got a working <a href="http://jsfiddle.net/96bEy/" rel="noreferrer">fiddle</a>. But it has a bug. </p>
  
  <pre><code>var str = 'This, is a test.'; 
  alert( removeLastComma(str) ); // should remain unchanged
  
  var str = 'This, is a test,'; 
  alert( removeLastComma(str) ); // should remove the last comma
  
  var str = 'This is a test,          '; 
  alert( removeLastComma(str) ); // should remove the last comma
  
  function removeLastComma(strng){        
      var n=strng.lastIndexOf(",");
      var a=strng.substring(0,n) 
      return a;
  }
  </code></pre>