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.180 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.179 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.178 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.177 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.176 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.175 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.174 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.173 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.172 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.171 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.170 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.169 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.167 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.166 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.165 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.164 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.163 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.162 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.161 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts
trackler-2.2.1.160 tracks/typescript/exercises/secret-handshake/secret-handshake.example.ts