Squares of array items
given an array myArray write a JS program to get the squares of each item in the given array
input1
[[1,2],[3,4][5,6]]
output1
[ [1,4],[9,6], [25, 36]]
"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 myArray = JSON.parse(readLine());
/* Please do not modify anything above this line */
/* Write your code here and log the output */
}
"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 myArray = JSON.parse(readLine());
/* Please do not modify anything above this line */
/* Write your code here and log the output */
const newArray = []
myArray.map(e => {
const arr = [];
e.map(k => arr.push(k*k))
newArray.push(arr)
})
console.log(newArray);
}
Comments
Leave a comment