Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 ";
- var numPaints = 0;
- var stencils = ["file", "command", "compile", "dir", "process"];
- for (var i = 0; i < stencils.length; i++) {
- var thisStencilUsed = 0;
- var stencil = stencils[i];
- while (string.indexOf(stencil) != -1) {
- string = string.replace(stencil, "");
- numPaints++;
- thisStencilUsed++;
- }
- console.log("Stencil " + stencil + " used " + thisStencilUsed + " times.");
- }
- var array = [];
- for (var i = 0; i < string.length; i++) {
- var char = string.charAt(i);
- if (array[char] == null) {
- array[char] = 0;
- }
- array[char]++;
- }
- var objects = [];
- function Stencil(char, freq) {
- this.char = char;
- this.freq = freq;
- }
- for (var x in array) {
- if (x != ' ') {
- objects.push(new Stencil(x, array[x]));
- }
- }
- objects.sort(compare);
- function compare(a, b) {
- return b.freq - a.freq;
- }
- console.log(objects);
- var stencilCount = 0;
- for (var i = 0; i < objects.length; i++) {
- numPaints += objects[i].freq;
- stencilCount += Math.floor(objects[i].freq / 20) + 1;
- }
- console.log(stencilCount + stencils.length);
- console.log(numPaints);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement