posted 11 years ago
However... I think it's very likely that the "indexOf" method works by "going through" the list, which is something you didn't seem to want in your original post. Or were you just looking for a solution which didn't require you yourself to write the code? If so, then Michael Dunn's solution is just fine.
(And yes, I do believe it's better to look for built-in solutions to ordinary problems like this one, rather than writing your own code. For one thing the built-in solutions already work, whereas code I write doesn't necessarily work the first time and needs to be tested and debugged. For another thing, the built-in solution has a chance of working better than the code I might write.)