Skip to content

Instantly share code, notes, and snippets.

@ruzli
Created May 20, 2019 13:52
Show Gist options
  • Save ruzli/c6e871bde860bfca4eb73ec1250684af to your computer and use it in GitHub Desktop.
Save ruzli/c6e871bde860bfca4eb73ec1250684af to your computer and use it in GitHub Desktop.
Median logging in console and log output
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