Life Experience

davidgk · updated June 13, 2021 · NodeJS
const lucky ={rangeRandom: 200,meters: 80, situation: 'lucky'}
const smart = {rangeRandom: 10,meters: 50, situation: 'smart'}
const effort = {rangeRandom: 3,meters: 20, situation: 'effort'}

class Runner {
    constructor(key){
        this.distance = 0;
        this.myKey = key // no importa.. es un tema de suerte
        this.advanceBy = {lucky: 0 , smart: 0 , effort: 0}
    }
    
    increaseAdvance(position) {
        this.distance += position.meters;
        this.advanceBy[position.situation] += 1
    }
}


const runner_a = new Runner(1)
const runner_b = new Runner(2)
const runner_c = new Runner(3)

const tries = 365

function getRandomArbitrary(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}

function addValueUser(val, position, runner){
    if (runner.myKey === val) {
        runner.increaseAdvance(position)
    }   
}

function addValue(val, position){
    addValueUser(val, position, runner_a)
    addValueUser(val, position, runner_b)
    addValueUser(val, position, runner_c)
}


for (i = 0; i < tries; i++) {
    const ramdomLucky = getRandomArbitrary(0, lucky.rangeRandom)
    const ramdomSmart = getRandomArbitrary(0, smart.rangeRandom)
    const ramdomEffort = getRandomArbitrary(0, effort.rangeRandom)
    addValue(ramdomLucky, lucky)
    addValue(ramdomSmart, smart)
    addValue(ramdomEffort, effort)    
}

function getMessage(runner) {
    return ', Distance: '+ runner.distance 
+ ' using lucky:'+ runner.advanceBy.lucky + ' times -- ' 
+ ' using smart:'+ runner.advanceBy.smart + ' times --' 
+ ' using effort:'+ runner.advanceBy.effort + ' times'
}

console.log('Runner A' + getMessage(runner_a)) 
console.log('Runner B' + getMessage(runner_b)) 
console.log('Runner C' + getMessage(runner_c)) 


    

Comments

Please sign up or log in to contribute to the discussion.