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

@monorail when i do things like this aesc calls them "caleb solutions"

@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

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.