Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function append(str, tab){
- if(tab.indexOf(str) != -1){
- var index = str.match(/\d+$/);
- if(index == null)
- index = "1";
- else {
- index = index[0];
- str = str.slice(0, -1 * index.length);
- }
- return append(str+(parseInt(index)+1), tab);
- }
- else
- tab.push(str);
- }
- var tab = ["string", "string1", "string2", "stringi", "stringu", "stringa" ];
- append('string', tab);
Advertisement
Add Comment
Please, Sign In to add comment