Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1.  
  2. alphabet = {
  3. A:'a',
  4. B:'b',
  5. C:'c',
  6. D:'d',
  7. E:'e',
  8. F:'f',
  9. G:'g',
  10. H:'h',
  11. I:'i',
  12. J:'j',
  13. K:'k',
  14. L:'l',
  15. M:'m',
  16. N:'n',
  17. O:'o',
  18. P:'p',
  19. Q:'q',
  20. R:'r',
  21. S:'s',
  22. T:'t',
  23. U:'u',
  24. V:'v',
  25. W:'w',
  26. X:'x',
  27. Y:'y',
  28. Z:'z'
  29. }
  30.  
  31. Object.assign(alphabet, {
  32. E: 'H',
  33. K: 'T',
  34. J: 'E',
  35.  
  36. S: 'O',
  37. Y: 'I',
  38. L: 'A',
  39. Z: 'N',
  40. N: 'L',
  41. P: 'U'
  42. });
  43.  
  44. text = `
  45. AJLPNYRJZJFLZYASGSKQGSMME
  46. JKEJPFSVLPJLKKEJELNNSPZKY
  47. NNYGNSGASGYZJGAKEYZYGASVW
  48. NJKSWSKECNLUJZKEJZEYCYZWS
  49. VOEKLGAHYKKJAZEJNYJZLKLGY
  50. ESPPJLAFHSPZJLFSVGJRJPYTL
  51. OYGJALZMJJKJPZUESSGJPLUEY
  52. NATYOEKZLYNEJPKMSEVGAPJAK
  53. SGZGLTJEYZCLGYSNL
  54. `;
  55.  
  56. a = text.replace(/\s/g, '').split('').reduce((acc, c) => { acc[c] = acc[c] ? acc[c] + 1 : 1; return acc;}, {})
  57. b = {};
  58. Object.keys(a).forEach(c => b[c] = parseInt(10000*a[c]/text.replace(/\s/g, '').length)/100)
  59. console.log(a);
  60. console.log(b);
  61.  
  62. res = '';
  63. for (c of text.replace(/\s/g, '')) {
  64. res += (alphabet[c] ? alphabet[c] : c);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement