JavaScript but it’s actually cool?!?! #coding

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

The definition of genius is taking the complex and making it simple. - Albert Einstein

AbdulelahAGR
Автор

Advice my teacher gave me: write each line of code as if a serial killer will be working on it after you.

If this was true, this dude is cooked

xvirqer
Автор

Cool idea, but it probably is worse in a benchmark because now you have to factor in allocating an array every time this is called.

logicalsparrow
Автор

sounds like something youd see in lambda calculus

m.guypirate
Автор

At best it's premature optimzation, trying to create branchless code. What probably happens is that it generates the exact same code as the ternary.

goswinvonbrederlow
Автор

that's why i hate technical tests,
in the real world, we use Math.min

Lkful
Автор

What is so cool about it? It doesn't improve performance (actually makes it worse) and it makes code difficult to read, since you have to spend time understanding what exactly this does.

mkedzier
Автор

Numbers instead of boolean types is an abomination.

johnandrea
Автор

Hate to burst the bubble but doing it the non-ternary way is WAYYYY less efficient. Creating an array like that may cause a heap allocation, possibly cause a page fault in memory. This is way less performant than a straight ternary statement. Either the person you're interviewing was trying to be "cute" or show off their skillz, or they truly were clueless. Either way, don't let them infect your codebase

leewilson
Автор

Whatever happened to the simple Math.min(a, b)?

xastley
Автор

Focused more on the weird finger than the code

im_not_a_bot_
Автор

how come you have coding channel and never plaid golfing? in golfing this trick used like every other time

Huxya
Автор

This example might be neat in isolation but imagine working on a big project with thousands of expressions like this one. You'd be swimming in code that takes a lot of brain energy to navigate.

twheys
Автор

No. I mean, yeah, it's pretty cool. But really, no. I mean, yeah. But no.

tombonner
Автор

It's not "creative use"... Whoever that was he or she made this worse. Instead of already created vars, simple types, they converted into an array object and then performed the basic crap that would only ever work on 2 item array... It's not the code readability it's a total stupidity because someone decided to convert simple vals into more memory intensive operation than ternary. Now imagine a bigger project and this "super genius" would contribute only by writing inefficient code... So yep, let's change the ternary to this crap code... Seriously?! 😳

Jake-hllm
Автор

this is a waste of JS engine resources! creates unnecessary array. also agree that it is unreadable. so finally, it is actually awful.

cloudless_mirror
Автор

What about Math.min? This ain't code golfing

anticom
welcome to shbcf.ru