Skip to content

Instantly share code, notes, and snippets.

@jakebromberg
Last active December 27, 2015 16:41
Show Gist options
  • Save jakebromberg/6e449023bbd4e0598524 to your computer and use it in GitHub Desktop.
Save jakebromberg/6e449023bbd4e0598524 to your computer and use it in GitHub Desktop.
import Foundation
import Swift
extension Int {
public func pow(exp: Int) -> Int {
return (0..<exp).reduce(1) { (acc, _) in
return acc * self
}
}
}
extension Array {
func split(pieces: Int) -> [ArraySlice<Element>] {
let ratio = count / pieces
var a = [ArraySlice<Element>]()
for num in startIndex.stride(to: count, by: ratio) {
a.append(self[num..<min(num + ratio, count)])
}
return a
}
}
print([1, 2, 3, 4, 5, 6, 7].split(3).reverse())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment