Write a program that removes duplicate characters and outputs when a single lowercase character string is input. Each character in the stripped string retains the order of the original string.
A string is entered on the first line.
ksekkset
Prints a string with duplicate characters removed on the first line.
kset
new Set()
function solution(s) {
let answer = '';
new Set(s).forEach((el) => (answer += el));
return answer;
}
indexOf()
function solution(s) {
let answer = '';
for (let i = 0; i < s.length; i++) {
// if s[i] is an only number, it should be i === s.indexOf(s[i])
// console.log(s[i], i, s.indexOf(s[i]));
if (s.indexOf(s[i]) === i) answer += s[i];
}
return answer;
}
ksekkset, k
3
function solution(s, v) {
let answer = 0;
let pos = s.indexOf(v);
while (pos !== -1) {
answer++;
pos = s.indexOf(v, pos + 1);
}
return answer;
}