summaryrefslogtreecommitdiff
path: root/src/better.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/better.js')
-rw-r--r--src/better.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/better.js b/src/better.js
new file mode 100644
index 0000000..dcd9234
--- /dev/null
+++ b/src/better.js
@@ -0,0 +1,39 @@
+const langs = require('./languages.json');
+
+function reverseObject(object) {
+ var newObject = {};
+ var keys = [];
+
+ for (var key in object) {
+ keys.push(key);
+ }
+
+ for (var i = keys.length - 1; i >= 0; i--) {
+ var value = object[keys[i]];
+ newObject[keys[i]]= value;
+ }
+
+ return newObject;
+}
+
+module.exports = (data) => {
+ matches = {}
+ splangs.forEach((e) => {
+ matches[e.code] = 0;
+ })
+
+ keys = Object.keys(data);
+
+ keys.forEach((key) => {
+ item = data[key];
+ if (typeof item.best.lvl1 != "undefined") {
+ matches[item.best.lvl1]++;
+ }
+ })
+
+ newmatches = Object.entries(matches)
+ .sort(([,a],[,b]) => a-b)
+ .reduce((r, [k, v]) => ({ ...r, [k]: v }), {});
+ newmatches = reverseObject(newmatches);
+ return newmatches;
+} \ No newline at end of file