| 123456789101112131415161718192021222324252627 |
- //
- // ArrayExtension.swift
- // CryptoSwift
- //
- // Created by Marcin Krzyzanowski on 10/08/14.
- // Copyright (c) 2014 Marcin Krzyzanowski. All rights reserved.
- //
- import Foundation
- extension Array {
-
- /** split in chunks with given chunk size */
- func chunks(chunksize:Int) -> [Array<T>] {
- var words = [[T]]()
- words.reserveCapacity(self.count / chunksize)
- for var idx = chunksize; idx <= self.count; idx = idx + chunksize {
- let word = Array(self[idx - chunksize..<idx]) // this is slow for large table
- words.append(word)
- }
- let reminder = Array(suffix(self, self.count % chunksize))
- if (reminder.count > 0) {
- words.append(reminder)
- }
- return words
- }
- }
|