Created
September 6, 2021 11:44
-
-
Save dorman99/4d636f42b71e5985d6473c977c2b18c0 to your computer and use it in GitHub Desktop.
remove duplicate string
This file contains hidden or 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 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