Answer to Question #169572 in HTML/JavaScript Web Application for Chandra sena reddy

Question #169572

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().

Input

  • The input will be a single line containing a string myString

Output

  • The output should be a single line containing an array of unique characters


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.


1
Expert's answer
2021-03-09T19:26:31-0500
"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);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS