Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const rows = ['qwertyuiopå', 'asdfghjklöä', 'zxcvbnm'];
- const charLists = [
- ...rows,
- ...rows.map(row => row.toUpperCase()),
- '1234567890'
- ];
- const transform = transformer => text =>
- text.split('').map(char => {
- const chars = charLists.find(list => list.includes(char));
- return chars
- ? transformer(chars.indexOf(char), chars)
- : char;
- }).join('');
- const shiftRight = transform((index, chars) => {
- const i = index + 1;
- return i < chars.length
- ? chars[i]
- : chars[0];
- });
- const shiftLeft = transform((index, chars) => {
- const i = index - 1;
- return i < 0
- ? chars[chars.length - 1]
- : chars[i];
- });
- console.log(shiftRight('Moi! testiä 123')); // => "Zpo! yrdyoa 234"
- console.log(shiftLeft('Zpo! yrdyoa 234')); // => "Moi! testiä 123"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement