This file contains 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
private func formatIP(with text: String) -> String { | |
let divider = "." | |
var ipBlocks = text.components(separatedBy: divider) | |
let lastBlock = ipBlocks.popLast() ?? "" | |
guard let number = Int(lastBlock), number > 0 else { | |
if let lastSymbol = text.last, | |
String(lastSymbol) == divider, | |
let lastIpBlock = ipBlocks.last, | |
!lastIpBlock.isEmpty { |
This file contains 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
class Car { | |
private var position = (x: 0, y: 0) | |
public func execute(_ move: Go) { | |
switch move.direction { | |
case "right": | |
self.position.x += move.distance! | |
case "left": |