const max = (a, b, c) => ([a, b, c].sort().pop());
if i'm writing something SOOO performance critical that i can't afford the extra One comparison that comes with a sort i'd write it as
function max(a, b, c) {
if (a > b) {
return Math.max(a, c);
}
return Math.max(b, c);
}
because at that point you're doing too many things for it to make sense as a one-liner
this is all assuming Math.max
can't take a third argument, or an array argument or something. which seems to be the assumption made in the premise
@monorail oh my fucking god Math.max can take a third argument in JavaScript fuck me
@wallhackio @monorail i thought i got it from you lol
@wallhackio @monorail anyway there is always [a, b, c].reduce(Math.max)
@wallhackio @monorail though actually you may need to explicitly wrap Math.max like (x,y) => Math.max(x,y) because reduce supplies extra args
@aescling @wallhackio i thought of this as well but i had it in my head that the time complexity was the same as sorting, which now that i've thought about it for one second is clearly untrue
@aescling @wallhackio but i'm still, like
it's three things. there's three of them
@wallhackio have you played the Zachtronics/Coincidence games
@monorail no, but they're on the ever-growing List
@wallhackio @monorail I like Clodsire's solution better, for what it's worth
What the Glaceon wrote just feels so wrong
IDK, I'm not a JavaScript programmer, it's probably an OK solution in terms of performance
It just feels so wrong instead of the obvious solution of using 2 ternary operators...
@vaporeon_ @wallhackio the problem with nested ternery operators is that every time you write code, you're setting yourself up to have to read it later
@monorail @wallhackio I found Clodsire's example pretty readable, but I guess that's because I use ternary operators all the time
@monorail @vaporeon_ i bet that I am Powerful enough to understand nested ternaries I wrote a year ago
@wallhackio @vaporeon_ i am capable of understanding all kinds of code
i think good code should be trivial to read
@wallhackio @vaporeon_ how are we on the sides of this argument that we're on when you chewed me out for my single-letter name for the client object in my mastodon bot
@monorail @vaporeon_ I actually agree with you, I am just being difficult because I am stupid enough to pester a 50m tall creature
@wallhackio @monorail @vaporeon_ 50m and growing, apparently
@aescling @wallhackio @vaporeon_ sometimes
@vaporeon_ @monorail well modern architecture is so performant that it is okay to always prefer elegance over performance
@wallhackio @monorail Though if Math.max can take 3 arguments, I guess that is the best way to solve it in JavaScript
@wallhackio @monorail no you call them that