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.119 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.118 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.117 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.116 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.115 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.114 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.113 tracks/javascript/exercises/rotational-cipher/example.js
trackler-2.2.1.111 tracks/javascript/exercises/rotational-cipher/example.js