find the first value
given an array myArray of positive integers, write a JS program to find the first smallest integer divisible 2 and 3 Log the number or Undefined.in case no integer is found divisible by 2 and 3
input1
[51,18,15,12]
output1
[12]
input2
[41,29,17,19,31]
output2
undefined
"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 */
let min = myArray[0], result = undefined, index = 0;
while (myArray.length) {
myArray.map((e, i)=> {
if (e < min) min = e;
index = i
})
if (min % 3 === 0 && min % 2 === 0) {
result = min;
break
}
myArray.splice(index, 1);
min = myArray[0];
}
console.log(result)
}
Comments
Leave a comment