Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- let result = '';
- let identifiers = new Set();
- function genCharArray(charA, charZ, arr) {
- var i = charA.charCodeAt(0), j = charZ.charCodeAt(0);
- for (; i <= j; ++i) {
- arr.push(String.fromCharCode(i));
- }
- }
- args.forEach(line => {
- let lineLength = line.length;
- let currentIdentifier = '';
- for (let i = 0; i < lineLength; i += 1) {
- if (line[i] === ';' && currentIdentifier.length != 0) {
- identifiers.add(currentIdentifier);
- currentIdentifier = '';
- }
- if (line[i] === ' ') {
- if (currentIdentifier.length != 0) {
- identifiers.add(currentIdentifier);
- currentIdentifier = '';
- }
- continue;
- }
- if (i > 0 && line[i] === ';' && line[i - 1] === ';') {
- continue;
- }
- if (line[i].match(/[a-z0-9_]/i)) {
- currentIdentifier += line[i];
- }
- result += line[i];
- }
- if (currentIdentifier.length != 0) {
- identifiers.add(currentIdentifier);
- }
- });
- let num = 0;
- let chars = [];
- genCharArray('a', 'z', chars);
- genCharArray('A', 'Z', chars);
- let len = 4000 - chars.length;
- for (let i = 0; i < len; i += 1) {
- chars.push(i);
- }
- for (let i of identifiers) {
- result = result.replace(i, chars[num].toString());
- num += 1;
- }
- console.log(result);
- console.log(result.length);
- }
- solve([
- 'hello;',
- '{this; is',
- ' ; an;;;example;',
- '}',
- 'of;',
- '{',
- 'KONPOT;',
- '{',
- 'Some_numbers;',
- '42;5;3}',
- '_}'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement