I feel like an idiot, but I need to filter my array, and then map those values, but thats O(2N) and it would make more sense to do it all in O(N) but I can't find a stock Array.prototype function
array.filter(item => !!item.revenue).map(item => item.revenue)
I can always write my own method but it would be best to use the performance optimized Array.prototype ones, if there is one
How about Array.prototype.reduce()?
arr.reduce((newArr, item) => {
if (!!item.revenue) {
newArr.push(item.revenue)
}
return newArr
}, []);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With