Skip to content

Instantly share code, notes, and snippets.

@rlazoti
Created June 3, 2014 03:19
Show Gist options
  • Save rlazoti/7c59a74b79590e2e6e9f to your computer and use it in GitHub Desktop.
Save rlazoti/7c59a74b79590e2e6e9f to your computer and use it in GitHub Desktop.
Swift test
import Foundation
func add(a: Int, b: Int) -> Int { return a + b }
func sub(a: Int, b: Int) -> Int { return a - b }
func calculate(a: Int, b: Int, fn: (Int, Int) -> Int) -> Int { return fn(a, b) }
let sumOfTwoNumbers = calculate(10, 20, add)
let subOfTwoNumbers = calculate(30, 28, sub)
println("10 + 20 = \(sumOfTwoNumbers)")
println("30 - 28 = \(subOfTwoNumbers)")
let people = ["ford", "zaphod", "arthur", "trillian"].map { $0.capitalizedString }
people.sort { $0 < $1 }
println(people)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment