arrRepeat function

List arrRepeat(
  1. dynamic array,
  2. int count
)

Repeats the data of an Array or Map a specific number of times and returns it as a 1d array.

Implementation

List<dynamic> arrRepeat(dynamic array, int count) {
  if (array.isEmpty || count < 1) {
    return [];
  }

  List<dynamic> result = [];

  for (int i = 0; i < count; i++) {
    if (array is Map) {
      result.add(array);
    } else {
      result.addAll(array);
    }
  }

  return result;
}