samedi 13 avril 2019

Unexpected results from an if statement within a for loop

I am writing some JavaScript (nothing fancy - I am a noob) and when I try to log my results to the console I am getting unexpected results. The else statement kicks in way more frequently than it should. for example, I am seeing that if i=3 and j=3 =>(x1+x2=6/100) then the else statement is being called, which of course it shouldn't do as 6/100 < 1. I'm probably being really dense, but any help would be appreciated.

Thanks.

export function arbitrageCalculator3Way(odds){

let x1=0;
let x2=0;
let x3=0;

let potentialMax=0;
let maxMin=0;
let holderCombo=[0,0,0];
let arbReturn =0;



for (var i=1;i<99;i++) //nearest percentage
{
    for (var j=1;j<99;j++) 
    {

        x2 = i/100;
        x3 = j/100;

        if(x2+x3<1){

            potentialMax = (Math.min(odds[0][0]*(1-x2-x3),odds[0][1]*x2,odds[0][2]*x3));

            if(potentialMax>maxMin)
            {
                maxMin=potentialMax;
                holderCombo=[1-x2-x3,x2,x3];

                console.log(maxMin);
                console.log(holderCombo);
                debugger;
            }



        }
        else{
            console.log("Hello");
            console.log(maxMin);
                console.log(holderCombo);
                debugger;
            break;
        }


    }

}
x1 = 1 -x2 - x3;
arbReturn=(maxMin-1)*100;

console.log(arbReturn); console.log(${x1} ${x2} ${x3}); ////hmmm error. debugger; return arbReturn;

}

Aucun commentaire:

Enregistrer un commentaire