Advertisement
wtmhahagd

Wall analyzer 2

Nov 25th, 2015
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. var string = "navigating directories cd - change dir ls - list files mkdir - new dir cp - copy file mv - move or rename file rm - delete file rm -rf - delete whole directory .. parent ~ home file processing touch - new empty file cat - print file head - start of file tail - end of file vim - gl hf grep - search in file zcat - view compressed file zip - zip compression system info man - detailed command guides id - about you time - program stopwatch date - system date + time running things python - run python javac - compile java gcc - compile c g++ - compile c++ processes ps xaf - process tree ps aux - show process pkill - kill process by name htop - process monitor commands ctrl+c - stop ctrl+z - pause !! - repeat last command ctrl+r - search command history ";
  2. var numPaints = 0;
  3. var stencils = ["file", "command", "compile", "dir", "process"];
  4.  
  5. for (var i = 0; i < stencils.length; i++) {
  6. var thisStencilUsed = 0;
  7. var stencil = stencils[i];
  8. while (string.indexOf(stencil) != -1) {
  9. string = string.replace(stencil, "");
  10. numPaints++;
  11. thisStencilUsed++;
  12. }
  13.  
  14. console.log("Stencil " + stencil + " used " + thisStencilUsed + " times.");
  15. }
  16.  
  17. var array = [];
  18. for (var i = 0; i < string.length; i++) {
  19. var char = string.charAt(i);
  20. if (array[char] == null) {
  21. array[char] = 0;
  22. }
  23. array[char]++;
  24. }
  25.  
  26. var objects = [];
  27.  
  28. function Stencil(char, freq) {
  29. this.char = char;
  30. this.freq = freq;
  31. }
  32.  
  33. for (var x in array) {
  34. if (x != ' ') {
  35. objects.push(new Stencil(x, array[x]));
  36. }
  37. }
  38.  
  39. objects.sort(compare);
  40.  
  41. function compare(a, b) {
  42. return b.freq - a.freq;
  43. }
  44.  
  45. console.log(objects);
  46.  
  47. var stencilCount = 0;
  48. for (var i = 0; i < objects.length; i++) {
  49. numPaints += objects[i].freq;
  50. stencilCount += Math.floor(objects[i].freq / 20) + 1;
  51. }
  52.  
  53. console.log(stencilCount + stencils.length);
  54. console.log(numPaints);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement