Skip to content

Instantly share code, notes, and snippets.

@daehn
Created October 8, 2015 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daehn/1968456423f53284cf07 to your computer and use it in GitHub Desktop.
Save daehn/1968456423f53284cf07 to your computer and use it in GitHub Desktop.
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