Swift Split An Array Into Chunks

[Solved] Swift Split An Array Into Chunks | Swift - Code Explorer | yomemimo.com
Question : swift split an array into chunks

Answered by : rens-wijnmalen

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)

Source : https://www.hackingwithswift.com/example-code/language/how-to-split-an-array-into-chunks | Last Update : Tue, 15 Feb 22

Answers related to swift split an array into chunks

Code Explorer Popular Question For Swift