I'm trying to use reduce function in order to find the max length array in arrays so I tried this approach at first but it didn't work
const arrays = [[1],[3,3,4],[3,4],[4,5],[6]]
let maxLength = arrays.reduce( (acc, cur) => {
return acc.length > cur.length ? acc.length : cur.length
})
console.log(maxLength) // output : 1
so I tried to get the length in another way and it worked
const arrays = [[1],[3,3,4],[3,4],[4,5],[6]]
let maxLength = arrays.reduce( (acc, cur) => {
return acc.length > cur.length ? acc : cur
}).length
console.log(maxLength) // output : 3
Can someone Explain what is the difference between the two approaches ?