Sha256: 93b44019393a5923f333967581cbfdc34f52010f50002f89ca71bae74a5fe1a6

Contents?: true

Size: 1.08 KB

Versions: 68

Compression:

Stored size: 1.08 KB

Contents

var RotationalCipher = function () {};

RotationalCipher.prototype.rotate = function (text, shiftKey) {
  if (text.length === 1) {
    if (text.charCodeAt(0) >= 97 && text.charCodeAt(0) <= 122) return this.rotateLowerCase(text, shiftKey);
    if (text.charCodeAt(0) >= 65 && text.charCodeAt(0) <= 90) return this.rotateUpperCase(text, shiftKey);
    return text;
  }
  return this.rotate(text.charAt(0), shiftKey) + this.rotate(text.slice(1), shiftKey);
};

RotationalCipher.prototype.rotateLowerCase = function (letter, shiftKey) {
  var rotatedLowerCase = String.fromCharCode(letter.charCodeAt(0) + shiftKey);
  if (rotatedLowerCase.charCodeAt(0) > 122) rotatedLowerCase = String.fromCharCode(rotatedLowerCase.charCodeAt(0) - 26);
  return rotatedLowerCase;
};

RotationalCipher.prototype.rotateUpperCase = function (letter, shiftKey) {
  var rotatedUpperCase = String.fromCharCode(letter.charCodeAt(0) + shiftKey);
  if (rotatedUpperCase.charCodeAt(0) > 90) rotatedUpperCase = String.fromCharCode(rotatedUpperCase.charCodeAt(0) - 26);
  return rotatedUpperCase;
};

module.exports = RotationalCipher;

Version data entries

68 entries across 68 versions & 1 rubygems

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