WAP where if element is even , multiply by 2 and if element is odd , multiply by 3.

let n = [12345]

function modifyArray(nums
    {   
        let arr = []
        nums.forEach((ele,index)=>{
            if(ele % 2 == 0){
                arr.push(ele*2)
            }
            else{
                arr.push(ele *3)
            }
            
        })
        return arr
    }
// console.log(arr);

console.log(modifyArray(n)) 



0 Comments