lodash analysis
  • Introduction
  • Tips
    • 高阶函数
    • 从 ECMAScript 中理解 Symbol 类型转换
  • Array
    • findLastIndex
    • map
  • Collection
    • countBy
    • findLast
    • flatMap
    • partition
    • reduce
  • Function
    • after
    • before
    • debounce
    • defer
    • delay
    • flip
    • memoize
    • negate
    • once
    • overArgs
    • throttle
  • Lang
    • isArguments
    • isArrayLike
    • isBuffer
    • isLength
    • isObject
    • isObjectLike
    • isSymbol
    • isTypedArray
    • isUndefined
    • toFinite
    • toNumber
  • Math
    • add
    • ceil
    • divide
    • floor
    • maxBy
    • mean
    • meanBy
    • minBy
    • multiply
    • round
    • subtract
    • sum
    • sumBy
  • Number
    • clamp
    • inRange
    • random
  • Object
    • keys
  • .internal
    • arrayLikeKeys
    • arrayReduce
    • baseAssignValue
    • baseEach
    • baseFindIndex
    • baseFlatten
    • baseFor
    • baseForOwn
    • baseInRange
    • baseReduce
    • baseSum
    • baseToNumber
    • baseToString
    • createMathOperation
    • createRound
    • getTag
    • isFlattenable
    • isIndex
    • nodeTypes
  • Date
    • now(已弃用)
Powered by GitBook
On this page
  1. Collection

flatMap

PreviousfindLastNextpartition

Last updated 6 years ago

Was this helpful?

CtrlK
  • 依赖
  • 源码
  • 相关链接

Was this helpful?

"It is our choices that show what we truly are, far more than our abilities." —@@jk_rowling

本文为 《lodash 源码阅读》 系列文章,后续内容会在 github 中发布,欢迎 star,gitbook 同步更新。

依赖

import baseFlatten from './.internal/baseFlatten.js';
import map from './map.js';
  • lodash 源码阅读 —— map

  • lodash 源码阅读 —— baseFlatten

源码

/**
 * 创建一个扁平化的数组
 * 这个数组的值来自collection(集合)中的每一个值经过 iteratee(迭代函数) 处理后返回的结果,并且扁平化合并。
 * iteratee 调用三个参数: (value, index|key, collection)。
 *
 * @since 4.0.0
 * @category Collection
 * @param {Array|Object} collection 迭代遍历的集合。
 * @param {Function} iteratee 每次迭代调用的函数。
 * 

相关链接

  • lodash 源码阅读 —— map

  • lodash 源码阅读 —— baseFlatten

@returns
{Array}
返回新扁平化数组。
*/
function flatMap(collection, iteratee) {
// 使用 map 遍历 collection 返回新的集合,再使用 baseFlatten 进行扁平化操作
return baseFlatten(map(collection, iteratee), 1);
}