map function

List map (
  1. List array,
  2. dynamic iteratee(
    1. dynamic element,
    2. int index,
    3. List array
    )
)

Creates an array of values by running each element of array thru iteratee. The iteratee is invoked with three arguments: (value, index, array).

square(n, index, array) {
  return n*n;
}
map([4, 8], square);
// Returns [16, 64]

Implementation

List map(
    List array, Function(dynamic element, int index, List array) iteratee) {
  int index = -1;
  int length = array.length;
  List result = List(length);

  while (++index < length) {
    result[index] = iteratee(array[index], index, array);
  }

  return result;
}