SHARE
TWEET

Algorithm that calculates the repetition of the letters

a guest May 22nd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
  2. var dictionary = {};
  3.  
  4. for(var i = 0; i < text.length; i++) {
  5.     var char = text[i].toLocaleLowerCase();
  6.  
  7.     if (char.toLocaleLowerCase() !== char.toUpperCase()) {
  8.         if (!dictionary[char]) {
  9.             dictionary[char] = +1;
  10.         } else {
  11.             dictionary[char]++;
  12.         }
  13.     }
  14. }
  15.  
  16. var sortable = [];
  17. for (var char in dictionary) {
  18.     sortable.push([char, dictionary[char]]);
  19. }
  20.  
  21. sortable.sort(function(a, b) {
  22.     return b[1] - a[1];
  23. });
  24.  
  25. console.log(sortable);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top