function renameFiles(names) {
  const newNames = [...names];
  function getResult(newNamess) {
    for (let i = 0; i < names.length; i++) {
      let sum = 0;
      for (let j = i + 1; j < newNamess.length; j++) {
        if (newNamess[i] === newNamess[j]) {
          sum += 1;
          newNames[j] = `${newNamess[j]}(${sum})`;
        }
      }
    }
  }
  while (new Set(newNames).size !== newNames.length) {
    getResult(newNames, names);
  }
  return newNames;
}
/**
 * There's a list of file, since two files cannot have equal names,
 * the one which comes later will have a suffix (k),
 * where k is the smallest integer such that the found name is not used yet.
 *
 * Return an array of names that will be given to the files.
 *
 * @param {Array} names
 * @return {Array}
 *
 * @example
 * For input ["file", "file", "image", "file(1)", "file"],
 * the output should be ["file", "file(1)", "image", "file(1)(1)", "file(2)"]
 *
 */
There's a list of file, since two files cannot have equal names,
the one which comes later will have a suffix (k),
where k is the smallest integer such that the found name is not used yet.

Return an array of names that will be given to the files.

@param {Array} names
@return {Array}


There ' s a list of file since two files cannot have equal names the one which comes later will have a suffix ( k ) where k is the smallest integer such that the found name is not used yet . Return an array of names that will be given to the files . @param { Array } names @return { Array }
function renameFiles(names) {
  const newNames = [...names];
  function getResult(newNamess) {
    for (let i = 0; i < names.length; i++) {
      let sum = 0;
      for (let j = i + 1; j < newNamess.length; j++) {
        if (newNamess[i] === newNamess[j]) {
          sum += 1;
          newNames[j] = `${newNamess[j]}(${sum})`;
        }
      }
    }
  }
  while (new Set(newNames).size !== newNames.length) {
    getResult(newNames, names);
  }
  return newNames;
}
function renameFiles ( names ) { const newNames = [ ... names ] ; function getResult ( newNamess ) { for ( let i = 0 ; i < names . length ; i ++ ) { let sum = 0 ; for ( let j = i + 1 ; j < newNamess . length ; j ++ ) { if ( newNamess [ i ] === newNamess [ j ] ) { sum += 1 ; newNames [ j ] = ` ${ newNamess [ j ] } ${ sum } ` ; } } } } while ( new Set ( newNames ) . size !== newNames . length ) { getResult ( newNames , names ) ; } return newNames ; }
There's a list of file, since two files cannot have equal names,
 the one which comes later will have a suffix (k),
 where k is the smallest integer such that the found name is not used yet.
There ' s a list of file since two files cannot have equal names the one which comes later will have a suffix ( k ) where k is the smallest integer such that the found name is not used yet .