Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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