Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. function solve(args) {
  2. let result = '';
  3. let identifiers = new Set();
  4. function genCharArray(charA, charZ, arr) {
  5. var i = charA.charCodeAt(0), j = charZ.charCodeAt(0);
  6. for (; i <= j; ++i) {
  7. arr.push(String.fromCharCode(i));
  8. }
  9. }
  10.  
  11. args.forEach(line => {
  12. let lineLength = line.length;
  13. let currentIdentifier = '';
  14.  
  15. for (let i = 0; i < lineLength; i += 1) {
  16. if (line[i] === ';' && currentIdentifier.length != 0) {
  17. identifiers.add(currentIdentifier);
  18. currentIdentifier = '';
  19. }
  20.  
  21. if (line[i] === ' ') {
  22. if (currentIdentifier.length != 0) {
  23. identifiers.add(currentIdentifier);
  24. currentIdentifier = '';
  25. }
  26.  
  27. continue;
  28. }
  29.  
  30. if (i > 0 && line[i] === ';' && line[i - 1] === ';') {
  31. continue;
  32. }
  33.  
  34. if (line[i].match(/[a-z0-9_]/i)) {
  35. currentIdentifier += line[i];
  36. }
  37.  
  38. result += line[i];
  39. }
  40.  
  41. if (currentIdentifier.length != 0) {
  42. identifiers.add(currentIdentifier);
  43. }
  44. });
  45.  
  46. let num = 0;
  47. let chars = [];
  48.  
  49. genCharArray('a', 'z', chars);
  50. genCharArray('A', 'Z', chars);
  51. let len = 4000 - chars.length;
  52. for (let i = 0; i < len; i += 1) {
  53. chars.push(i);
  54. }
  55.  
  56. for (let i of identifiers) {
  57. result = result.replace(i, chars[num].toString());
  58. num += 1;
  59. }
  60.  
  61. console.log(result);
  62. console.log(result.length);
  63. }
  64.  
  65. solve([
  66. 'hello;',
  67. '{this; is',
  68. ' ; an;;;example;',
  69. '}',
  70. 'of;',
  71. '{',
  72. 'KONPOT;',
  73. '{',
  74. 'Some_numbers;',
  75. '42;5;3}',
  76. '_}'
  77. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement