title: String increment: increment the last string by one
body: <p>the purpose of this code is to to write a function which increments a string, to create a new string. If the string already ends with a number, the number should be incremented by 1. If the string does not end with a number the number 1 should be appended to the new string. e.g. "foo123" --> "foo124" or "foo" --> "foo1".
  With my code below, pretty much all my test cases are passed except a corner case for "foo999" did not print out "foo1000". I know that there should be a way to do with regex to fix my problem, but I am not too familiar with it. Can anyone please help?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function incrementString (input) {
    var reg = /[0-9]/;
    var result = "";
    if(reg.test(input[input.length - 1]) === true){
      input = input.split("");
      for(var i = 0; i &lt; input.length; i++){
          if(parseInt(input[i]) === NaN){
              result += input[i];
          }
          else if(i === input.length - 1){
              result += (parseInt(input[i]) + 1).toString();
          }
          else{
              result += input[i];
          }
      }
      return result;
    }
    else if (reg.test(input[input.length - 1]) === false){
      return input += 1;
    }
  }</code></pre>
  </div>
  </div>
  </p>