Created
January 18, 2020 08:32
-
-
Save kentcdodds/aacbf3ca4859301ed6cfabdca05f1e85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const duplicates = filesAndHashes.filter((file1, index1, array) => { | |
return array.some( | |
(file2, index2) => index1 !== index2 && file1.hash === file2.hash, | |
) | |
}) | |
const groups = duplicates.reduce((groups, {filepath, hash}) => { | |
groups[hash] = groups[hash] || [] | |
groups[hash].push(filepath) | |
return groups | |
}, {}) | |
// vs | |
const filesByHash = {} | |
for (const {filepath, hash} of filesAndHashes) { | |
filesByHash[hash] = filesByHash[hash] || [] | |
filesByHash[hash].push(filepath) | |
} | |
const groups = {} | |
for (const hash in filesByHash) { | |
if (filesByHash[hash].length > 1) { | |
groups[hash] = filesByHash[hash] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment