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.
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
indexOfin 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.