SHARE
TWEET

Untitled

a guest Feb 21st, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extension Array {
  2.     func toChunks(of size: Int) -> [[Element]] {
  3.         return stride(from: 0, to: count, by: size).map {
  4.             Array(self[$0 ..< Swift.min($0 + size, count)])
  5.         }
  6.     }
  7. }
  8.  
  9. let numbers = Array(1...12)
  10. let result = numbers.toChunks(of: 5)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top