Answer to Question #314561 in HTML/JavaScript Web Application for hari

Question #314561

given an object person containing a person details, write a JS program to log the name, address & nicknames count

input

{ 'name':'Pranay', 'address':{'city':'Mumbai','state':'maharastra'}, 'nicknames':['nani','chanti']}

output

pranay is from mumbai,maharastra

pranay has 2 nicknames


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

}

function main() {

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

 /* Write your code here and log the output */

}


1
Expert's answer
2022-03-19T13:57:16-0400
"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++];


}


function main() {


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


 function personDetails (obj) {
   const name = obj.name.toLowerCase();
   const countNicknames = obj.nicknames.length;
   const address = Object.values(obj.address).join(',').toLowerCase();


   return `${name} is from ${address}\n${name} has ${countNicknames} nicknames`
 }


 console.log(personDetails(person)); // { 'name':'Pranay', 'address':{'city':'Mumbai','state':'maharastra'}, 'nicknames':['nani','chanti']}


}

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
APPROVED BY CLIENTS