Created
October 8, 2015 00:54
-
-
Save daehn/1968456423f53284cf07 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 | |
extension Array where Element : IntegerType { | |
var sum: Element { | |
return reduce(0, combine: +) | |
} | |
var odds: [Element] { | |
return filter { $0 % 2 != 0 } | |
} | |
var evens: [Element] { | |
return filter { $0 % 2 == 0 } | |
} | |
func every(n: Element) -> [Element] { | |
var count : Element = 0 | |
return filter { _ in count++ % n == 0 } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment