4 ms·
> I don't see how this is better: const alivePlayers = filter(x => x.isAlive)(players); const scoresOfalivePlayers = map(x => x.score)(alivePlayers);
by vikingerik 4y ago
> I don't see how this is better:
const alivePlayers = filter(x => x.isAlive)(players);
const scoresOfalivePlayers = map(x => x.score)(alivePlayers);
const highestScore = tryMax(scoresOfalivePlayers);
I think this is way better. The variable names tell me at an instantaneous glance what each clause is doing. I don't have to spend mental effort delving into what's going on with the lambdas, or scan back and forth to find a comment that may or may not be there or out of date if it is.
Furthermore, I'd wrap all of those lines together into a getHighestScore() function as well. That makes the complexity exactly as visible or as abstracted as you want at any given moment. The name of that function tells you what the aggregate of the operations is doing, and you can go look inside that function if you want to see the individual steps.