Answer to Question #303038 in HTML/JavaScript Web Application for Sagar

Question #303038

take a function to check no is prime or not from array and then is number is prime add 1 to element if not then multiply by 2..note: Use arrow function to add or multiply element part


1
Expert's answer
2022-02-27T04:23:40-0500
const checkPrime = (arr) => {
    arr = arr.map((e) => {
        if (e > 0) {
            let temp = []
            for (let i = 1; i <= e; i++) {
                if (e % i == 0) temp.push(i)
            }
            if (temp.length == 2) {
                return e + 1
            } else {
                return e * 2
            }
        } else {
            return e * 2
        }
    })
    return arr
}


const numbers = [-2, 5, 4, 3, 11, 13, 19]


console.log(checkPrime(numbers))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS