# All files / utils flatMap.ts

100% Statements 13/13
100% Branches 0/0
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19

    4x

    20x
    20x

    32x
    63x
    63x

    20x

     /*
      Equivalent to `flatten(xs.map(f))`.
    */
    export const flatMap = <X, Y>(
      xs: X[],
      f: (x: X, i: number, xs: X[]) => Y[]
    ): Y[] => {
      const result = []
      const yss = xs.map(f)

      for (const ys of yss) {
        for (const y of ys) {
          result.push(y)
        }
      }

      return result
    }