Answer to Question #295982 in HTML/JavaScript Web Application for chethan

Question #295982

the goal of this code is to quickly get you off the ground with the array method map().

input

the input will be single line containing an array myArray.

output

the output will be single line containing the newArray.

constaints

Strings should be given in quotes


input1

[ 1, 'David' 10, {'points':97}, 25, 'alphabet', true]

output1

[2, 'string' 20, 'object', 50, 'string', 'boolean']


"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() {

 const myArray = JSON.parse(readLine().replace(/'/g, '"'));

// Write your code here

  }


1
Expert's answer
2022-02-11T07:43:59-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++];
}


function main() {
  const myArray = JSON.parse(readLine().replace(/'/g, '"'));
 // Write your code here
  let newArray = myArray.map(function(el) {
    if (typeof el == 'number') {
      return el * 2;
    }
    else {
      return typeof el;
    }
  });
  console.log(newArray)
}

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