I can't seem to figure out why my code only works when there's just 2 arrays being computed. But when I'm adding another array, I get a result of "NaN".
Here's my code:
cycleComputation (trades) {
if (! trades.length) {
return 0;
}
const ups = trades;
if (ups.length) {
return ups.map(net => {
return {
realized: parseFloat(net.realizedPL),
unrealized: net.unrealizedPL ? parseFloat(net.unrealizedPL) : 0
}
})
.reduce((a,b) => (a.realized + a.unrealized) + (b.realized + b.unrealized));
} else {
return 0;
}
}