Your job is 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.

Examples:

foo -> foo1

foobar23 -> foobar24

foo0042 -> foo0043

Attention: If the number has leading zeros the amount of digits should be considered.



Your Solution:
function incrementString (input) {
  // return incrementedString
}




Your Test Cases:
Test.assertEquals(incrementString("foobar000"), "foobar001");
Test.assertEquals(incrementString("foo"), "foo1");
Test.assertEquals(incrementString("foobar001"), "foobar002");
Test.assertEquals(incrementString("foobar1"), "foobar2");

@@ -485,16 +485,767 @@
 dString%0A
+%0A%0A%0Afunction incrementString (input) %7B%0A  // return incrementedString%0A  if (input.length %3E 0 && /%5Cd/.test(input%5Binput.length - 1%5D)) %7B%0A    // ends with number, increment it%0A    var numericPart = input.match(/%5Cd+$/)%5B0%5D,%0A        textPart = input.substr(0, input.length - numericPart.length);%0A    var oldNumberLength = numericPart.length;%0A    var newNumber = parseInt(numericPart, 10) + 1,%0A        newNumberLength = (newNumber + '').length;%0A    if (newNumberLength %3E= oldNumberLength) %7B%0A      // no need to add leading zeros%0A      return textPart + newNumber;%0A    %7D else %7B%0A      var leadingZeroes = oldNumberLength - newNumberLength;%0A      return textPart + (new Array(leadingZeroes + 1)).join('0') + newNumber;%0A    %7D%0A  %7D else %7B%0A    return input + '1';%0A  %7D%0A
 %7D%0A%0A%0A%0A%0AYo

complete kata challenge