Last active
December 27, 2015 16:41
-
-
Save jakebromberg/6e449023bbd4e0598524 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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