Answer to Question #303199 in HTML/JavaScript Web Application for king

Question #303199

Sports Data

write a JS program to consolidate the data so that each student should participate in only one sport if duplicates entries are found consider the latest entry

input1

[['Arjun','Cricket'],['Ronalodo','Football'],['pradeep','Volleyball']

output1

{Arjun: 'Cricket',Ronaldo:'Football',Pradeep:'Volleyball'}


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++];

}


function main() {

 let sportsData = JSON.parse(readLine().replace(/'/g, '"'));


 /* Please do not modify anything above this line */


 /* Write your code here */

}


1
Expert's answer
2022-03-05T11:46:54-0500
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++];
}

function main() {
    let sportsData = JSON.parse(readLine().replace(/'/g, '"'));
    /* Please do not modify anything above this line */

    /* Write your code here */
    const myObj = {};

    sportsData.map(e => {
        myObj[e[0]] = e[1];
    });
    
    console.log(myObj)
}

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