function incrementT60Bananas(uid, result, userData) { try { let best60; try { best60 = Math.max( ...userData.personalBests.time[60].map((best) => best.wpm) ); if (!Number.isFinite(best60)) { throw "Not finite"; } } catch (e) { best60 = undefined; } if (best60 != undefined && result.wpm < best60 - best60 * 0.25) { // console.log("returning"); } else { //increment // console.log("checking"); User.findOne({ uid: uid }, (err, user) => { if (user.bananas === undefined) { user.bananas.t60bananas = 1; } else { user.bananas.t60bananas += 1; } user.save(); }); } } catch (e) { console.log( "something went wrong when trying to increment bananas " + e.message ); } }