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.0.5 tracks/ecmascript/exercises/atbash-cipher/example.js
trackler-2.2.0.4 tracks/ecmascript/exercises/atbash-cipher/example.js
trackler-2.2.0.3 tracks/ecmascript/exercises/atbash-cipher/example.js
trackler-2.2.0.2 tracks/ecmascript/exercises/atbash-cipher/example.js
trackler-2.2.0.1 tracks/ecmascript/exercises/atbash-cipher/example.js