Question
Explain this code: var numArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] var primeArray = [] function isPrime(number = []){ for
Explain this code:
var numArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var primeArray = []
function isPrime(number = []){
for (var i = 0; i < number.length; i++) {
if (number[i] === 2 && number[i]!= 1) {
primeArray.push(number[i])
console.log("This is a prime number");
console.log(number[i]);
}
else if (number[i] % 2 != 0 && number[i]!= 1){
primeArray.push(number[i])
console.log("This is a prime number");
console.log(number[i]);
}
else{
console.log("This is not a prime number")
console.log(number[i]);
}
}
}
isPrime(numArray)
console.log(" ")
console.log("Prime Array")
console.log(primeArray)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started