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; }