hrthimrn commited on
Commit
8e4e7e1
·
1 Parent(s): 1b2cb3c

Refactor count functions to sort results by count percentage

Browse files
Files changed (1) hide show
  1. main.js +12 -3
main.js CHANGED
@@ -45,7 +45,10 @@ function countSingle(str){
45
  singCount[letter] = 1;
46
  }
47
  }
48
- let countString = Object.entries(singCount)
 
 
 
49
  .map(([key, value]) => `${key}: ${value} (${(value / totalLetters * 100).toFixed(2)}%)`)
50
  .join("\n");
51
 
@@ -71,7 +74,10 @@ function countDigrams(str) {
71
  }
72
  }
73
 
74
- let digramString = Object.entries(digramCounts)
 
 
 
75
  .map(([key, value]) => `${key}: ${value} (${(value / totalDigrams * 100).toFixed(2)}%)`)
76
  .join("\n");
77
 
@@ -96,7 +102,10 @@ function countTrigrams(str) {
96
  }
97
  }
98
 
99
- let trigramString = Object.entries(trigramCounts)
 
 
 
100
  .map(([key, value]) => `${key}: ${value} (${(value / totalTrigrams * 100).toFixed(2)}%)`)
101
  .join("\n");
102
 
 
45
  singCount[letter] = 1;
46
  }
47
  }
48
+ const sortedCount = Object.entries(singCount)
49
+ .sort((a, b) => b[1] - a[1]);
50
+
51
+ let countString = sortedCount
52
  .map(([key, value]) => `${key}: ${value} (${(value / totalLetters * 100).toFixed(2)}%)`)
53
  .join("\n");
54
 
 
74
  }
75
  }
76
 
77
+ const sortedCounts = Object.entries(digramCounts)
78
+ .sort((a, b) => b[1] - a[1]);
79
+
80
+ let digramString = sortedCounts
81
  .map(([key, value]) => `${key}: ${value} (${(value / totalDigrams * 100).toFixed(2)}%)`)
82
  .join("\n");
83
 
 
102
  }
103
  }
104
 
105
+ let sortedCounts = Object.entries(trigramCounts)
106
+ .sort((a, b) => b[1] - a[1]);
107
+
108
+ let trigramString = sortedCounts
109
  .map(([key, value]) => `${key}: ${value} (${(value / totalTrigrams * 100).toFixed(2)}%)`)
110
  .join("\n");
111