Table of contents
7-2 Remove duplicate characters
Original title:
After removing duplicate characters from the given string, sort the characters in ASCII code order from small to large and then output.
Input format :
Input is a non-empty string (less than 80 characters) terminated by a carriage return.
Output format:
Output the result string after dereordering.
.
Problem-solving ideas:
Problem-solving ideas:
- Remove duplicates through set
- Custom sorting
.
JavaScript (node) code:
const r = require("readline");
const rl = r.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('',(input)=>{
const uniqueChars = [...new Set(input)];
const sortedStr = uniqueChars.sort((a, b) => a.charCodeAt(0) - b.charCodeAt(0)).join('');
console.log(`${
sortedStr}`);
rl.close();
});
.