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
| func occurrencesOfCharacters(in text: String) -> [Character: Int] { | |
| var dict: [Character: Int] = [:] | |
| for key in text { | |
| if dict[key] == nil { | |
| dict[key] = 1 | |
| }else{ | |
| dict[key]! += 1 | |
| } | |
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
| var dict = ["Eins" : 1, "Zwei": 2] | |
| func isInvertible(_ dictionary: [String: Int]) -> Bool { | |
| var isItTrue = true | |
| var array : [Int] = [] | |
| for numbers in dict.values { | |
| if array.contains(numbers) == false { |
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
| func divideIfWhole(_ value: Int, by divisor: Int) -> Int? { | |
| var answer: Int? = 0 | |
| let divisible = value % divisor | |
| switch divisible { | |
| case 0: | |
| answer = value / divisor | |
| default: | |
| answer = nil | |
| } | |
| return answer |