GitHub 6248★

Remove duplicate lines of a text document

JavaScript version

const removeDuplicateLines = (str) => Array.from(new Set(str.split(/\r?\n/))).join('\n');

TypeScript version

const removeDuplicateLines = (str: string): string => Array.from(new Set(str.split(/\r?\n/))).join('\n');

Examples

removeDuplicateLines(`one
three
two
three
one
four
`
);

/* Output */
/*
one
three
two
four
*/
Follow me on and to get more useful contents.