Sha256: 2c4cdedeb45626427f2d0b0dc09834ac9efe359e7a5a6954a82463014b862e83

Contents?: true

Size: 618 Bytes

Versions: 185

Compression:

Stored size: 618 Bytes

Contents

const LETTERS = 'abcdefghijklmnopqrstuvwxyz';
const REVERSED_LETTERS = [...LETTERS].reverse().join('');

function insertSpacing(s, interval) {
  const matcher = new RegExp(`.{1,${interval}}`, 'g');
  return s.match(matcher).join(' ');
}

function invert(character) {
  if (character.match(/\d/)) {
    this.push(character);
  } else {
    this.push(LETTERS[REVERSED_LETTERS.indexOf(character)]);
  }
}

export default {
  encode: (s) => {
    let encoded;
    const characters = [];
    [...s.toLowerCase()].forEach(invert, characters);
    encoded = insertSpacing(characters.join(''), 5);
    return encoded;
  },
};

Version data entries

185 entries across 185 versions & 1 rubygems

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