Open RobLoach opened 3 years ago
Well, start
can already be a negative number which means, in effect, that it starts searching forwards from index str.bytes.count + start
.
So, if we are to have a version which searches backwards from the end of the string, it will have to be called lastIndexOf
or similar.
Do you think we need lastIndexOf()
in List
too?
It would make sense to add it to both I'd think.
Yes, if we do one then we should do both.
List.lastIndexOf()
would also be easier to implement as you wouldn't need to worry about being in the middle of a UTF-8 byte sequence when searching backwards through a string's bytes.
Allow for backwards searching with
.indexOf(search, start)
by passing a negative number.Alternatively, we could take JavaScript's approach of
lastIndexOf
instead.