From 7f627a21b2beb5cf9f72c77eccb151ef66231d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nemanja=20Vlahovic=CC=81?= Date: Wed, 31 Aug 2016 14:02:17 +0200 Subject: [PATCH] Update Count Occurrences to Swift 3 --- Count Occurrences/CountOccurrences.playground/Contents.swift | 4 ++-- Count Occurrences/CountOccurrences.swift | 2 +- Count Occurrences/README.markdown | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Count Occurrences/CountOccurrences.playground/Contents.swift b/Count Occurrences/CountOccurrences.playground/Contents.swift index b90ba12ce..cbb43c868 100644 --- a/Count Occurrences/CountOccurrences.playground/Contents.swift +++ b/Count Occurrences/CountOccurrences.playground/Contents.swift @@ -1,6 +1,6 @@ //: Playground - noun: a place where people can play -func countOccurrencesOfKey(key: Int, inArray a: [Int]) -> Int { +func countOccurrencesOfKey(_ key: Int, inArray a: [Int]) -> Int { func leftBoundary() -> Int { var low = 0 var high = a.count @@ -53,7 +53,7 @@ func createArray() -> [Int] { } } } - return a.sort(<) + return a.sorted() } for _ in 0..<10 { diff --git a/Count Occurrences/CountOccurrences.swift b/Count Occurrences/CountOccurrences.swift index 57c75c735..10dd12c4f 100644 --- a/Count Occurrences/CountOccurrences.swift +++ b/Count Occurrences/CountOccurrences.swift @@ -2,7 +2,7 @@ Counts the number of times a value appears in an array in O(lg n) time. The array must be sorted from low to high. */ -func countOccurrencesOfKey(key: Int, inArray a: [Int]) -> Int { +func countOccurrencesOfKey(_ key: Int, inArray a: [Int]) -> Int { func leftBoundary() -> Int { var low = 0 var high = a.count diff --git a/Count Occurrences/README.markdown b/Count Occurrences/README.markdown index be8c2061e..90a9ec2f3 100644 --- a/Count Occurrences/README.markdown +++ b/Count Occurrences/README.markdown @@ -22,7 +22,7 @@ The trick is to use two binary searches, one to find where the `3`s start (the l In code this looks as follows: ```swift -func countOccurrencesOfKey(key: Int, inArray a: [Int]) -> Int { +func countOccurrencesOfKey(_ key: Int, inArray a: [Int]) -> Int { func leftBoundary() -> Int { var low = 0 var high = a.count