dropLastWhile method

List<E> dropLastWhile(
  1. bool predicate(
    1. E element
    )
)

Returns a new list containing all elements except last elements that satisfy the given predicate.

Implementation

List<E> dropLastWhile(bool Function(E element) predicate) {
  int? endIndex;
  for (var i = lastIndex; i >= 0; i--) {
    if (!predicate(this[i])) {
      endIndex = i;
      break;
    }
  }
  if (endIndex == null) return [];
  return sublist(0, endIndex + 1);
}