Function flatMapDeep

  • Recursively maps each element in an array using a provided iteratee function and then deeply flattens the resulting array.

    Type Parameters

    • T

      The type of elements within the array.

    • U

      The type of elements within the returned array from the iteratee function.

    Parameters

    • arr: readonly T[]

      The array to flatten.

    • iteratee: ((item: T) => U)

      The function that produces the new array elements.

        • (item): U
        • Parameters

          • item: T

          Returns U

    Returns ExtractNestedArrayType<U>[]

    A new array that has been flattened.

    const result = flatMapDeep([1, 2, 3], n => [[n, n]]);
    // [1, 1, 2, 2, 3, 3]