Sha256: 663b0b371df3c060654b5108c1e45d0f70ae152529ab214573ea68fdd34b8291

Contents?: true

Size: 1020 Bytes

Versions: 66

Compression:

Stored size: 1020 Bytes

Contents

class HandShake {
    allCommands = [
        'wink',
        'double blink',
        'close your eyes',
        'jump',
        'REVERSE'
    ]

    shakeWith: string[] = []

    constructor(handshake: number) {
        if (typeof handshake !== 'number') {
            throw new Error('Handshake must be a number')
        }

        this.shakeWith = this.calculateHandshake(handshake)
    }

    commands() {
        return this.shakeWith
    }

    calculateHandshake(handshake: number) {
        const shakeWith = []

        for (let i = 0; i < this.allCommands.length; i++) {
            const currentCommand = this.allCommands[i]
            const handshakeHasCommand = (handshake & Math.pow(2, i))

            if (handshakeHasCommand) {
                if (currentCommand === 'REVERSE') {
                    shakeWith.reverse()
                } else {
                    shakeWith.push(this.allCommands[i])
                }
            }
        }
        return shakeWith
    }
}

export default HandShake

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.138 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.137 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.136 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.135 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.134 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.133 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.132 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.131 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.130 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.129 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.128 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.127 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.126 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.125 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.124 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.123 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.122 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.121 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.120 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts