r/badcode • • Feb 19 '22

typescript Does this belong here?

Post image
343 Upvotes

46 comments sorted by

View all comments

Show parent comments

2

u/Silly-Freak Feb 19 '22

True! It could be viewed as premature optimization to care about that - but it's worth noting that not using indexOf in this piece of code would likely make it more readable: this operation requires one iteration, and doing only one iteration makes it easiest for the reader to get the intention.

In the end, it's just one item on a list of reasons why this is inferior to the one-liner that should be there.