String Incrementer

Published by Jaime Segura in

Write a function which increments a string to create a new string.

  • If the string ends with a number, the number should be incremented by 1.
  • If the string doesn't end with a number, 1 should be added to the new string.
  • If the number has leading zeros, the amount of digits should be considered.

Examples

incrementString("foo") ➞ "foo1"

incrementString("foobar0009") ➞ "foobar0010"

incrementString("foo099") ➞ "foo100"

Notes

N/A

Watch a quick demo on how Edabit works.