1.
You are given a string (STR) of length N, consisting of only the lower case English alphabet. Your task is to remove all the duplicate occurrences of characters in the string.
Code:-
let setFn = function (str){
let s = new Set();
for(let i=0; i<str.length;i++){
s.add(str[i]);
}
let chars = s
for(char of chars)
console.log(char);
}
setFn('abcadeecfb');
2.
You are given a string (STR) of length N, you have to print the count of all alphabet.(using maps).
Code:-
let s="abcadeecfb"
let map = new Map()
for(let i=0;i < s.length;i++){
if(map.has(s[i])){
let value = map.get(s[i])
map.set(s[i], value+1)
}
else{
map.set(s[i], 1)
}
}
for(let [k,v] of map){
console.log(k+"="+v);
}