title: Find the duplicate string in the array and add an incrementing number at the end
body: <p>I'm working in javascript &amp; trying to figure out an algorithm to append incremental numbers to strings, based on existing strings in the program.</p>
  <p>Input:</p>
  <pre><code>['Untitled Form', 'Untitled Form - 1', 'Untitled Form - 5', 'Untitled Form - 3', 'Untitled Form - 4', &quot;Untitled Form&quot;];
  </code></pre>
  <p>So say the user wants to add another string to this list, and they've selected &quot;Untitled Form&quot; as the string to add. So given the input and the existing list, the algorithm would search in the list to check if there is any incrementing number missing e.g In the above code the &quot;Untitled Form - 2&quot; is missing, It should return &quot;Untitled Form - 2&quot; as the new string to add.</p>
  <p>Output:</p>
  <pre><code>['Untitled Form', 'Untitled Form - 1', 'Untitled Form - 5', 'Untitled Form - 3', 'Untitled Form - 4', &quot;Untitled Form - 2&quot;];
  </code></pre>
  <p>It's the same function as in Windows Explorer where you keep adding New Folders (&quot;New Folder (1)&quot;, &quot;New Folder (2)&quot; and on and on)</p>
  <p>I have a solution for this problem but I think it is not very efficient and the algorithm also checks for the highest number and adds the incremental number after that is &quot;Untitled Form - 6&quot;.</p>