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