Sha256: 076541c040c1c7581c34bfe07b2bf7875390a6815e00a92c3fac64560c61d110

Contents?: true

Size: 711 Bytes

Versions: 188

Compression:

Stored size: 711 Bytes

Contents

struct SecretHandshake {

    var commandValue: Int
    var commandValues = [1: "wink", 2: "double blink", 4: "close your eyes", 8: "jump"]

    init(_ commandValue: Int) {
        self.commandValue = commandValue
    }

    var shouldReverse: Bool { return (commandValue & 16) != 0 }

    var commands: [String] { return commandsFunc() }

    private func commandsFunc() -> [String] {
        var commands = [String]()
        for key in Array(commandValues.keys).sorted( by: < ) where (commandValue & key) != 0 {
            commands.append(commandValues[key]!)
        }

        if shouldReverse {
            return Array(commands.reversed())
        } else {
            return commands
        }
    }
}

Version data entries

188 entries across 188 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.179 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.178 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.177 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.176 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.175 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.174 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.173 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.172 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.171 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.170 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.169 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.167 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.166 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.165 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.164 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.163 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.162 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.161 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.2.1.160 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift