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 */
}
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)
}
Comments
Leave a comment