Skip to content

Instantly share code, notes, and snippets.

@ad1992
Last active April 26, 2024 07:59
Show Gist options
  • Save ad1992/802ce394b636a8b48077e776b6b7f339 to your computer and use it in GitHub Desktop.
Save ad1992/802ce394b636a8b48077e776b6b7f339 to your computer and use it in GitHub Desktop.
Find duplicates in a file
const fs = require("fs");
const filePath = process.argv[2];
if (!filePath) {
console.error("Please provide a file path");
process.exit(1);
}
const data = fs.readFileSync(filePath, "utf8");
const data_array = data.trim().split("\n");
const duplicates = data_array.filter((item, index, self) => {
return self.indexOf(item) !== index;
});
console.log(duplicates);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment