Sha256: b7e0d0861c7cfa25b141b870d32052054604c0a1e2207169d9315676013d77ae

Contents?: true

Size: 408 Bytes

Versions: 117

Compression:

Stored size: 408 Bytes

Contents

class RotationalCipher {

  static rotate(text, shift) {
    return [...text].map((c) => {
      const isUpper = c.match(/[A-Z]/);
      const isAlpha = c.match(/[a-z]/i);
      const charShift = (isUpper ? 'A' : 'a').charCodeAt(0);

      return isAlpha ?
        String.fromCharCode((((c.charCodeAt(0) - charShift) + shift) % 26) + charShift) : c;
    }).join('');
  }

}

export default RotationalCipher;

Version data entries

117 entries across 117 versions & 1 rubygems

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