Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function zsay(s) {
- function z(token) {
- switch (token[0]) {
- case 'zext':
- return zify(token[1]).toLowerCase();
- case 'zeep':
- return token[1];
- }
- }
- return zeparate(s).map(z).reduce((a,b) => a + b);
- }
- function zeparate(s) {
- function group(c) {
- return 'abcedefghijklmnopqrstuvwxyzABCEDEFGHIJKLMNOPQRSTUVWXYZ0123456789[]'.indexOf(c) != -1;
- }
- var body = s;
- var res = [];
- var ztype = undefined;
- var val = undefined;
- while (body) {
- if (group(body[0])) {
- ztype = 'zext';
- val = span(group, body);
- } else {
- ztype = 'zeep';
- val = span((c) => !group(c), body);
- }
- body = val[1];
- res.push([ztype, val[0]]);
- }
- return res;
- }
- function span(test, m) {
- var border = 0;
- for (var i = 0; i < m.length; i++) {
- if (!test(m[i]))
- break;
- border++;
- }
- return [m.substring(0, border), m.substring(border, m.length)];
- }
- function zify(s) {
- var body = s;
- while (true) {
- var len = body.length;
- if (len < 4) {
- return 'z'.repeat(4 - len) + body;
- } else if (len == 4) {
- return 'z' + body.substring(1, body.length);
- } else if (hasVowel(body)) {
- body = dropVowel(body);
- } else {
- body = body.substring(1, body.length);
- }
- }
- }
- function hasVowel(s) {
- for (var i = 0; i < s.length; i++)
- if (isVowel(s[i]))
- return true;
- return false;
- }
- function dropVowel(s) {
- for (var i = 0; i < s.length; i++)
- if (isVowel(s[i]))
- return s.replace(new RegExp(s[i], ''), '');
- return s;
- }
- function isVowel(c) {
- return 'aeiouAEIOU'.indexOf(c) != -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement