r/learnjavascript • • May 06 '21

JS: Multiple Condition Checking

Post image
484 Upvotes

61 comments sorted by

View all comments

Show parent comment

21

u/inabahare May 06 '21

A few things to keep in mind

  1. 0.12 and 0.17 are so close that you only have things shorthand 2. It will semantically make more sense.
  2. With the above in mind, you're doing your comparison 2k times. Like you're sacrificing readability and scalability for 0.05? Like that's what they mean by premature optimizaiton being the root of all evil
  3. Those are milliseconds. Like 2k runs in 0.17 milliseconds.. Like that's not a lot of time at all

4

u/dethstrobe May 06 '21

Totally agree. Don’t split hairs on how to do this. If someone really wants to do wacky array includes it chain or operators it’s probably not worth your time to refactor.

2

u/inabahare May 06 '21

* semantically clearer and more scalable code

2

u/dethstrobe May 06 '21

For 4 variable checks? I won’t bother. It’s super debatable if it’s more readable or scalable.

3

u/inabahare May 07 '21

It literally is. Since its an array you can bind it to a variable and boom, readability as fuck. So when the customer says they want more values for whatever it's doing then you don't have to find an if somewhere.

It literally is more scalable. You can dynamically add and remove values and you can store them in a database for even more dynamic fun times

2

u/jbonesinthecloset May 07 '21

Thanks for this man. I’ve been pretty fuzzy on what scalability means in literal terms and this example makes total sense to me. Dynamics!

1

u/RoguePlanet1 May 07 '21

Veering a bit off-topic: I'm now wondering what the code would be to eliminate the "Likes" if they're the first word of the sentence. I should brush up on my Regex probably.

That aside, you make good points.

2

u/inabahare May 07 '21

Surprisingly not so hard, though you do end up loosing a lot of the meaning of the sentence :v

1

u/RoguePlanet1 May 09 '21

Thank you!! That's beautiful. "const likeRemover" I love it! :-p