Skip to content

Instantly share code, notes, and snippets.

@pedrogk
Created September 26, 2015 00:58
Show Gist options
  • Save pedrogk/94cd850c7346b4c0fcb9 to your computer and use it in GitHub Desktop.
Save pedrogk/94cd850c7346b4c0fcb9 to your computer and use it in GitHub Desktop.
Funciones
func getBound(anArray: [Int], test: (Int, Int) -> Bool) -> Int {
var bound = anArray[0]
for item in anArray[1..<anArray.count] {
if test(item, bound) {
bound = item
}
}
return bound
}
func greaterThan(a: Int, b: Int) -> Bool {
return a > b
}
func lessThan(a: Int, b: Int) -> Bool {
return a < b
}
let anArray = [52, -234, 177, 23, -545, 16, -8, 23, 3, -1]
var aFunction = greaterThan
var bound = getBound(anArray, aFunction) // bound = 177
aFunction = lessThan
bound = getBound(anArray, aFunction) // bound = -545
func chooseFunction(select: Int) -> (Int, Int) -> Bool {
return select == 1 ? greaterThan : lessThan
}
aFunction = chooseFunction(2)
aFunction(4, 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment