If can write it in a single line of code I'm gonna do it

@vaporeon_ const max = (a, b, c) => a < b ? b < c ? c : b : a < c ? c : a;

@wallhackio Personally I would've split it into 2 lines to make it easier to read, but it's also fine like this 👍

Does your code often need to compare specifically 3 items?

@vaporeon_ I would never actually use this for a serious project I was just amusing myself by writing it in a single indecipherable line

This specific thing I was doing needed it. Except then I realized later actually I didn't need it lol so I got rid of it

@wallhackio > I would never actually use this for a serious project

Why not?

@vaporeon_ I would write it more clearly if it were something serious

@wallhackio By adding parentheses? Or splitting it across 2 lines?

@vaporeon_ if I were serious I would write it like
const max = (a, b, c) => a < b
? b < c
? c
: b
: a < c
? c
: a;

or I would use an if else for the "outer" condition so there is no nested ternary

@wallhackio That's too many lines, in my opinion :psyduck:

I would've written it like this:

const max = (a, b, c) => a < b ? (b < c ? c : b)                                
: (a < c ? c : a);
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.