tracks/ecmascript/exercises/simple-cipher/example.js in trackler-2.2.0.0 vs tracks/ecmascript/exercises/simple-cipher/example.js in trackler-2.2.0.1

- old
+ new

@@ -1,9 +1,9 @@ const ALPHA = 'abcdefghijklmnopqrstuvwxyz'; function generateKey() { - return Array.apply(null, Array(100)) + return Array(...Array(100)) .map(() => ALPHA[Math.floor(Math.random() * ALPHA.length)]) .join(''); } function xCode(key, inText, sign) { @@ -16,22 +16,21 @@ } const mod = (n, m) => (n % m + m) % m; export default function (key) { - if (typeof key === 'undefined') { key = generateKey(); - } else if (key.length === 0 || key.match(/[^a-z]/, "g")) { - throw new Error("Bad key"); + } else if (key.length === 0 || key.match(/[^a-z]/, 'g')) { + throw new Error('Bad key'); } return { - key: key, - encode: function (plainText) { + key, + encode(plainText) { return xCode(this.key, plainText, 1); }, - decode: function (encodedText) { + decode(encodedText) { return xCode(this.key, encodedText, -1); - } - } + }, + }; }