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


Expert's answer

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))
LATEST TUTORIALS
APPROVED BY CLIENTS