Post

flatMap

flatMap

중첩 배열을 한 배열로 평평하게 만들거나, 옵셔널 배열을 변환

1. 중첩 배열을 평탄화

1
2
3
4
5
6
7
let nestedArray = [[1, 2, 3], [4, 5], [6, 7, 8]]
let flatArray = nestedArray.flatMap { $0 }

print(flatArray) // 출력: [1, 2, 3, 4, 5, 6, 7, 8]


This post is licensed under CC BY 4.0 by the author.