const fs = require('fs'); let average = (array) => array.reduce((a, b) => a + b) / array.length; function tryrem(file) { try { data = JSON.parse(fs.readFileSync(file)); } catch (e) { console.log("Failed to save, removing file"); fs.unlinkSync(file); tryrem(file); } } module.exports = (percs, words, file, silent) => { if (typeof silent == "undefined") { silent = false; } tryrem(file); keys = Object.keys(percs); keys2 = Object.keys(data); for (var i=0; i { if (!data["words"].includes(word)) { newwords.push(word); } }) data["words"] = [...data["words"], ...newwords]; if (!silent) console.log("Recalculating averages..."); for (var i=0; i