Answer to Question #295974 in HTML/JavaScript Web Application for GumanSingh

Question #295974

Double the numbers

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

input

  • the input will be single line containing an array myArray

output

  • the output will be single line containg the newArray

constraints

  • strings should be given in quotes


sample input1

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


sample output1

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


function readLine() {

 return inputString[currentLine++];

}


function main() {

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


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


 // Write your code here

  

}


1
Expert's answer
2022-02-11T07:43:56-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(data) {
    if (typeof data != 'number') {
      return typeof data;
    }
    else {
      return data * 2;
    }
  });
  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