Double the numbers
the goal of this code is to get quickly off the ground with array method map().
input
output
constraints
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
}
"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)
}
Comments
Leave a comment