Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

if array has multiple duplicate value number them accordingly

var res = renameFiles(keys);
        function renameFiles(arr){
          var count = {};
          arr.forEach(function(x,i) {
            if ( arr.indexOf(x) !== i ) {
              var c = x in count ? count[x] = count[x] + 1 : count[x] = 1;
              var j = c + 1;
              var k = x + '(' + j + ')';

              while( arr.indexOf(k) !== -1 ) k = x + '(' + (++j) + ')';
              arr[i] = k;
            }
          });
          return arr;
        }
Comment

PREVIOUS NEXT
Code Example
Javascript :: express search query 
Javascript :: mongoose limit 
Javascript :: node if file exists 
Javascript :: install react native gifted charts 
Javascript :: if input value is null do something 
Javascript :: javascript onclick to another page div 
Javascript :: react navigation navigator types 
Javascript :: send file in patch axios react native 
Javascript :: ngmodel onchange 
Javascript :: get screen resolution jquery 
Javascript :: hex to rgba in js 
Javascript :: html iframe and JS contentwindow 
Javascript :: get page link angular 
Javascript :: copy to clipboard js 
Javascript :: jquery if data attribute exists 
Javascript :: how can we update time in react js 
Javascript :: add char in specific index stirng javascript 
Javascript :: javascript write text 
Javascript :: settext javascript 
Javascript :: altv rpc 
Javascript :: ionic 3 alert 
Javascript :: datatables integration 
Javascript :: queryselector a tag with text 
Javascript :: disable eslint specific rule 
Javascript :: print value in jquery 
Javascript :: convert date online in moment js 
Javascript :: empty input of clone jquery 
Javascript :: jquery remove link href 
Javascript :: javascript quicksort 
Javascript :: gulp run sequence 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =