I have an array with this format:
let array = [{length:0},{length:5},{length:5},{length:10},{length:5}]
let sum = array.filter(x=>x.length).reduce((a,b)=>a.length + b.length, 0)
let count = array.filter(x=>x.length).length
console.log(sum,count,sum/count)
What I need is to filter the values > 0 and calculate an average based on those, but it always gets NaN for sum
and consequently for the average I need. I started from this answer here.
Thanks for any suggestion.