implemented lastIndexOf startting from a given index