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

let n = [1, 2, 3, 4, 5]

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