Jika array memiliki beberapa nomor nilai duplikatnya sesuai
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;
}
Bloody Barracuda