Answers for "swift split an array into chunks"

0

swift split an array into chunks

extension Array {
    func chunked(into size: Int) -> [[Element]] {
        return stride(from: 0, to: count, by: size).map {
            Array(self[$0 ..< Swift.min($0 + size, count)])
        }
    }
}
let numbers = Array(1...100)
let result = numbers.chunked(into: 5)
Posted by: Guest on February-08-2022

Code answers related to "swift split an array into chunks"

Code answers related to "Swift"

Browse Popular Code Answers by Language