
😎풀이
paths를 경로와 파일들로 분리
- 파일명과 본문 내용 분리
- 본문 내용이 같은 파일을 전체 경로와 함께 저장
- 본문 내용이 중복된 파일에 한해서 반환
function findDuplicate(paths: string[]): string[][] {
const fileDescMap = new Map<string, string[]>()
for(const path of paths) {
const [pathName, ...files] = path.split(' ')
for(const file of files) {
const idx = file.indexOf('(')
const fileName = file.slice(0, idx)
const fileDesc = file.slice(idx + 1, -1)
fileDescMap.set(fileDesc, [...(fileDescMap.get(fileDesc) ?? []), pathName + '/' + fileName])
}
}
return [...fileDescMap.values()].filter(files => files.length > 1)
};