3 ms·
arr.indexOf("thing") > -1 ... this one is hardly related to zero-indexing. If indexOf returned 0, this would be equally inelegant.
by junke 10y ago
arr.indexOf("thing") > -1
... this one is hardly related to zero-indexing. If indexOf returned 0, this would be equally inelegant.
- pwdisswordfish 10y agoAnd if indexOf returned null or undefined when the value is not found, this could not even be expressed with an ordering relation.
- junke 10y agoWhich is ... great? what is your point?
- pwdisswordfish 10y agoThat whether an element was found in a list or not has nothing to do with the order relation on the type of indices. Conceptually, it's a completely distinct case; in a more solid type system it would be captured by an option type. This becomes especially evident when you attempt to generalise this searching operation to arbitrary maps.