-
-
Save BitChop/166c63295d04ee450b5493b5f3d0a468 to your computer and use it in GitHub Desktop.
Bust Statistics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config = {}; | |
var debug = false; | |
let history = engine.getState().history; | |
let busts = []; | |
let padding = Array(6).join(' '); | |
engine.on('GAME_ENDED', onGameEnded); | |
for (let i = 0; i < history.length; i++) { | |
busts.push(history[i].bust); | |
} | |
function onGameEnded() { | |
busts.push(engine.history.first().bust) | |
outputStats(); | |
} | |
function outputStats() { | |
if (debug) { log("[" + JSON.stringify(busts) + "]["+busts.length+"]"); } | |
log("High : " + pad(padding, busts.max()) | |
+" | Low : " + pad(padding, busts.min()) | |
+" | Mean : " + pad(padding, busts.mean()) | |
+" | Median : " + pad(padding, busts.median()) | |
+" | Mode : " + pad(padding, busts.mode()) + ""); | |
} | |
function pad(pad, str, padLeft) { | |
if (typeof str === 'undefined') return pad; | |
if (padLeft) { | |
return (pad + str).slice(-pad.length); | |
} else { | |
return (str + pad).substring(0, pad.length); | |
} | |
} | |
Array.prototype.min = function () { | |
return Math.min.apply(null, this); | |
} | |
Array.prototype.max = function () { | |
return Math.max.apply(null, this); | |
} | |
Array.prototype.mean = function () { | |
if (this.length >= 1) { | |
let sum = 0; | |
for (let i = 0; i < this.length; i++) { | |
sum += this[i]; | |
} | |
return (sum / this.length); | |
} | |
return -1; | |
} | |
var numberSort = function (a, b) { | |
return a - b; | |
}; | |
Array.prototype.median = function () { | |
if (this.length >= 1) { | |
let median = this.slice().sort(numberSort); | |
if ((median.length % 2) == 0) { | |
return (((median[median.length / 2] + median[(median.length / 2) - 1])) / 2); | |
} else { | |
return (median[Math.floor(median.length / 2)]) | |
} | |
} | |
return -1; | |
} | |
Array.prototype.mode = function () { | |
let modeMap = {}; | |
let maxEl = this[0], maxCount = 1; | |
for (let i = 0; i < this.length; i++) { | |
let el = this[i]; | |
if (modeMap[el] == null) { | |
modeMap[el] = 1; | |
} else { | |
modeMap[el]++; | |
} | |
if (modeMap[el] > maxCount) { | |
maxEl = el; | |
maxCount = modeMap[el]; | |
} | |
} | |
if (maxCount == 1) { | |
return -1; | |
} | |
return maxEl; | |
} | |
outputStats(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment