re: More readable conditional with Array.includes() VIEW POST


Perhaps worth noting is that there is a performance penalty with Array.prototype.includes. Such a "membership check" can iterate across the length of the array, especially in instances where the argument passed does not exist.

In such a scenario, it may be advisable (depending on how often this is done), to convert to a set and perform these membership checks against that. The example you used seem to be constant versus a list of values that are not yet known until runtime.


Wow!!! Nice.

I didn't know. Thanks for contribute


Ah! If you didn't, Gabriel -- it may be worth your effort in covering some basic data structures and algorithms and algorithmic complexity (in both time and space). This isn't as big a deal when operating on just the front-end (browser) with small chunks of data, but if you ever use JS (Node) on the backend, this is important and also in instances where the UI is comprised of a LOT of data in a single-page app -- think Facebook. I've seen people do multiple nesting of for-loops (in Ruby) that took down an instance of a worker which typically equates to lost earnings due to downtime

code of conduct - report abuse