Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>
# assert a.last_index_of_from(20, 2) == 1
# assert a.last_index_of_from(20, 1) == 1
# assert a.last_index_of_from(20, 0) == -1
- fun last_index_of_from(item: nullable Object, pos: Int): Int
- do
- var res = -1
- var p = 0
- var i = iterator
- while i.is_ok do
- if p>pos then break
- if i.item == item then res = p
- i.next
- p += 1
+ fun last_index_of_from(item: nullable Object, pos: Int): Int do
+ var i = pos
+ while i >= 0 do
+ if self[i] == item then return i
+ i -= 1
end
- return res
+ return -1
end
# Two sequences are equals if they have the same items in the same order.
# Returns -1 if not found
#
# DEPRECATED : Use self.chars.last_index_of_from instead
- fun last_index_of_from(item: Char, pos: Int): Int
- do
- var iter = self.chars.reverse_iterator_from(pos)
- while iter.is_ok do
- if iter.item == item then return iter.index
- iter.next
- end
- return -1
- end
+ fun last_index_of_from(item: Char, pos: Int): Int do return chars.last_index_of_from(item, pos)
# Gets an iterator on the chars of self
#