Ad
Code
Diff
  • let abbrevName: (String) -> String = { $0.split(separator: " ")
                                             .compactMap { $0.first?.uppercased() }
                                             .joined(separator: ".") }
    • func abbrevName(_ name: String) -> String {
    • return name
    • .split(separator: " ")
    • .compactMap { $0.first?.uppercased() }
    • .joined(separator: ".")
    • }
    • let abbrevName: (String) -> String = { $0.split(separator: " ")
    • .compactMap { $0.first?.uppercased() }
    • .joined(separator: ".") }
Code
Diff
  • let isPerfectSquare: (Int) -> Bool = { pow(pow(CGFloat($0), 0.5), 2) == CGFloat($0) }
    • func isPerfectSquare(_ input: Int) -> Bool {
    • let inputAsDouble = Double(input)
    • return inputAsDouble.squareRoot().rounded() == inputAsDouble.squareRoot()
    • }
    • let isPerfectSquare: (Int) -> Bool = { pow(pow(CGFloat($0), 0.5), 2) == CGFloat($0) }
Code
Diff
  • import Glibc // for random()
    
    let a = { print(random()) }
    • import Glibc // for random()
    • let a = random()
    • print(a)
    • let a = { print(random()) }
Code
Diff
  • let hello = { print("Hello Swift 5!") }
    • func hello() {
    • print("Hello Swift 5!")
    • }
    • let hello = { print("Hello Swift 5!") }