Swift - Prefix

2020. 7. 13. 10:19Language/Swift

반응형

prefix(_:)

Returns a subsequence, up to the specified maximum length, containing the initial elements of the collection.

컬렉션의 초기 요소를 포함하는 지정된 최대 길이까지 하위 시퀀스를 반환한다.

 

func prefix(_ maxLength: Int) -> ArraySlice<Element>

 

let numbers = [1, 2, 3, 4, 5]
print(numbers.prefix(2))
// Prints "[1, 2]"
print(numbers.prefix(10))
// Prints "[1, 2, 3, 4, 5]"
반응형

'Language > Swift' 카테고리의 다른 글

Swift - starts  (0) 2020.07.13
Swift - 고급() 연산자  (0) 2020.07.07
Swift - zip  (0) 2020.07.06
Swift - flatMap, compactMap  (0) 2020.07.02
Swift - stride  (0) 2020.07.01