Saturday 13 May 2017

Why flatten isn't working?

I have read the code in how to flatten an array in MDN in JS. And works fine, but I don't understand why isn't working in this case:

const data = [null, ['a', 'b', 'c']]
const flattened = data.reduce((acc, cur) => {
    if(null != cur)
        acc.concat(cur)
}, [])

And this error:

TypeError: Cannot read property 'concat' of undefined

How to correct this?



via Lucas Almeida Carotta

No comments:

Post a Comment