Guest User

Untitled

a guest
Jun 8th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     function append(str, tab){
  2.         if(tab.indexOf(str) != -1){
  3.             var index = str.match(/\d+$/);
  4.             if(index == null)
  5.                 index = "1";
  6.             else {
  7.                 index = index[0];
  8.                 str = str.slice(0, -1 * index.length);
  9.             }
  10.  
  11.             return append(str+(parseInt(index)+1), tab);
  12.         }
  13.         else
  14.             tab.push(str);
  15.     }
  16.    
  17.     var tab = ["string", "string1", "string2", "stringi", "stringu", "stringa" ];
  18.     append('string', tab);
Advertisement
Add Comment
Please, Sign In to add comment