flatMap 实际上是先 map 再 flat
// 扁平化一层Array.prototype.myFlat=function(){return this.reduce((sum,cur)=>sum.concat(cur),[])}Array.prototype.myFlatMap = function (mapper) {return this.map(mapper).myFlat();};console.log(["it's Sunny in", "", "California"].myFlatMap(x => x.split(" ")));// ['it's', 'Sunny', 'in', '', 'California']console.log([1, 2, [3], 4].flatMap((x) => x + 1));console.log([1, 2, [3], 4].myFlatMap((x) => x + 1));// [2, 3, '31', 5]
