MultipleOddByTwo function

**I’m new to ES6 javascript syntax ,I’m trying to get the odd numbers in the following array and then multiply by 2 using reduce method but it’s giving me “cannot read property ‘push’ of undefined” error. Any help please.

**

const multiplyOddByTwo = (arr) => {
  return arr.reduce((acc,curr) => {
    if(curr % 2 === 0){
      acc.push(curr);
    }else{
      acc.push(curr * 2)
    }
  },[])
} 

console.log(multiplyOddByTwo([1,2,3]));

Your function inside of reduce has no return value. When your function has no return value, the return value is undefined. Without a return value, your accumulator becomes undefined.

1 Like

Thanks for your help,I got it

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.