isContiguous<T> static method

bool isContiguous<T>(
  1. List<T> list,
  2. List<T> values
)

Implementation

static bool isContiguous<T>(List<T> list, List<T> values) {
  if (list.isEmpty) return false;

  List<int> indices = list.map((e) => values.indexOf(e)).toList();
  indices.sort();

  for (int i = 0; i < indices.length - 1; i++) {
    if (indices[i + 1] - indices[i] != 1) {
      return false;
    }
  }
  return true;
}