Sha256: 7e6a664dabacc772d8d12ca1d407ee05d9fee6d8474e1dd7231412a3daed4aee

Contents?: true

Size: 736 Bytes

Versions: 130

Compression:

Stored size: 736 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: < ) {
            if (commandValue & key) != 0 {
                commands.append(commandValues[key]!)
            }
        }

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

Version data entries

130 entries across 130 versions & 1 rubygems

Version Path
trackler-2.0.8.30 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.29 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.28 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.27 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.26 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.24 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.23 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.22 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.21 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.20 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.19 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.18 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.17 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.16 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.15 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.14 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.13 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.12 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.11 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift
trackler-2.0.8.10 tracks/swift/exercises/secret-handshake/Sources/SecretHandshakeExample.swift