Created
June 3, 2014 03:19
-
-
Save rlazoti/7c59a74b79590e2e6e9f to your computer and use it in GitHub Desktop.
Swift test
This file contains hidden or 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 | |
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