@modern-kit/utils
Version:
1 lines • 1.46 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","sources":["../../../src/array/flatMap/index.ts"],"sourcesContent":["import { flatten } from '../flatten';\n\n/**\n * 각 배열 요소를 iteratee 함수로 매핑하고 지정된 깊이까지 결과를 평탄화합니다.\n *\n * @template T - 배열 요소의 유형입니다.\n * @template U - iteratee 함수에서 반환되는 배열 요소들의 타입입니다.\n * @template D - 평탄화 깊이의 유형입니다.\n * @param {T[] | readonly T[]} arr - 평탄화할 중첩 배열입니다.\n * @param {(item: T) => U} iteratee - 새로운 배열 요소를 생성하는 함수입니다.\n * @param {D} [depth=1] - 평탄화할 깊이입니다. 기본값은 1입니다.\n * @returns {FlatArray<U[], D>[]} - 평탄화된 새로운 배열을 반환합니다.\n *\n * @example\n * const arr = [1, 2, 3];\n *\n * flatMap(arr, (item: number) => [item, item]);\n * // [1, 1, 2, 2, 3, 3]\n *\n * flatMap(arr, (item: number) => [[item, item]], 2);\n * // [1, 1, 2, 2, 3, 3]\n */\nexport function flatMap<T, U, D extends number = 1>(\n arr: T[] | readonly T[],\n iteratee: (item: T) => U,\n depth: D = 1 as D\n): FlatArray<U[], D>[] {\n return flatten(\n arr.map((item) => iteratee(item)),\n depth\n );\n}\n"],"names":[],"mappings":";;AAsBO,SAAS,OAAA,CACd,GAAA,EACA,QAAA,EACA,KAAA,GAAW,CAAA,EACU;AACrB,EAAA,OAAO,OAAA;AAAA,IACL,IAAI,GAAA,CAAI,CAAC,IAAA,KAAS,QAAA,CAAS,IAAI,CAAC,CAAA;AAAA,IAChC;AAAA,GACF;AACF;;;;"}