Filter Unique Characters
Given a string
myString as an input, write a JS program to find the unique characters from the myString.
Quick Tip
You can use the array method indexOf().
Sample Input 1
Was it a cat I saw?
Sample Output 1
[
'W', 'a', 's', ' ',
'i', 't', 'c', 'I',
'w', '?'
]
Sample Input 2
I did, did I?
Sample Output 2
[ 'I', ' ', 'd', 'i', ',', '?' ]
the out put should appeared same as shown in sample output's
/* This is a javaScript question, and I will also send the code with function that have to complete :-*/
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
function main() {
const myString = readLine();
/* complete thefunction */
}
Please help me.
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
function main() {
const myString = readLine();
/* complete thefunction */
let arr = myString.split('');
let col = new Set(arr);
let res = Array.from(col);
console.log(res);
}
Comments
Leave a comment