-
-
Save BitChop/4d0098b52d8c7f2fbf2d2c7bd3554f7e to your computer and use it in GitHub Desktop.
bustabit median helper function
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
| engine.median = function (span) { | |
| let arr = engine.history.slice(0, (span ? Math.max(1, Math.min(50, span)) : 50)).map(a => a.bust).sort((a, b) => { return a - b }) | |
| let mid = arr.length / 2, med = mid % 1 ? arr[mid - 0.5] : (arr[mid - 1] + arr[mid]) / 2; | |
| return med; | |
| }; | |
| // Example Usage | |
| log(`Last 25 Bust Median: ${engine.median(25)}`); | |
| log(`Last 50 Bust Median: ${engine.median()}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment