Sha256: 79f6bf81b1b0f98a079f8e9296a844a094cc699c941b2b74a99b03497b1bccbd

Contents?: true

Size: 670 Bytes

Versions: 133

Compression:

Stored size: 670 Bytes

Contents

export default class RotationalCipher {
    static rotate(text: string, shiftBy: number) {
        return [...text]
            .map((c) => {
                const isUpper = c.toUpperCase() === c
                const isAlpha = c.match(/[a-z]/i)
                const caseCharCode = (isUpper ? "A" : "a").charCodeAt(0)
                if (isAlpha) {
                    const charCode = c.charCodeAt(0)
                    return String.fromCharCode(
                        (charCode - caseCharCode + shiftBy) % 26 + caseCharCode
                    )
                } else {
                    return c
                }
            })
            .join("")
    }
}

Version data entries

133 entries across 133 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.179 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.178 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.177 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.176 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.175 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.174 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.173 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.172 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.171 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.170 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.169 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.167 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.166 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.165 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.164 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.163 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.162 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.161 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts
trackler-2.2.1.160 tracks/typescript/exercises/rotational-cipher/rotational-cipher.example.ts