Product of Array Items
Testcase1 :Sample Input 1
[1, 2, 3]
Sample Output 1
1 * 2 * 3 = 6
Testcase2 :Sample Input 2
[-1, -2, -3]
Sample Output 2
-1 * -2 * -3 = -6
note : it must satisfy any input given with different cases
"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 integers = JSON.parse(readLine());
/* 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() {
let myArray = JSON.parse(readLine().replace(/'/g, '"'));
if (myArray.length > 0) {
let res = myArray[0].toString();
let buf = myArray[0];
for (let i = 1; i < myArray.length; i++) {
res += " * " + myArray[i].toString();
buf *= myArray[i];
}
console.log(res + " = " + buf);
}
}
Comments
Leave a comment