Skip to content

Instantly share code, notes, and snippets.

@dorman99
Created September 6, 2021 11:44
Show Gist options
  • Save dorman99/4d636f42b71e5985d6473c977c2b18c0 to your computer and use it in GitHub Desktop.
Save dorman99/4d636f42b71e5985d6473c977c2b18c0 to your computer and use it in GitHub Desktop.
remove duplicate string
const fs = require("fs");
const file = fs.readFileSync("str.txt", "utf-8");
const removeDuplicateChar = (str) => {
return str.filter((v, idx) => {
const f = str.lastIndexOf(v);;
if (f && idx !== f) {
str.splice(f, 1);
}
return v;
});
}
console.log(removeDuplicateChar(file.split("")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment