Created
May 20, 2019 13:52
-
-
Save ruzli/c6e871bde860bfca4eb73ec1250684af to your computer and use it in GitHub Desktop.
Median logging in console and log output
This file contains 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
Array.prototype.median = function (arr) { | |
arr.sort((a, b) => a - b); | |
var pivot = Math.floor(arr.length / 2); | |
return arr.length % 2 ? arr[ pivot ] : (arr[ pivot - 1 ] + arr[ pivot ]) / 2; | |
} | |
class Median{ | |
constructor(context) { | |
this.context = context | |
this.history = [] | |
} | |
show(multiplier){ | |
this.history.push(multiplier) | |
let games_amount = this.history.length | |
this.context.log(`Rolls: ${games_amount} | Median: ${this.history.median(this.history).toFixed(2)}`) | |
console.log(`Rolls: ${games_amount} | Median: ${this.history.median(this.history).toFixed(2)}`) | |
} | |
} | |
var median = new Median(this) | |
while(true){ | |
const {multiplier} = await this.bet(100, 1.01) | |
median.show(multiplier) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment