Я пишу некоторый JavaScript (ничего особенного - я нуб), и когда я пытаюсь записать свои результаты в консоль, я получаю неожиданные результаты. Оператор else срабатывает чаще, чем следует. например, я вижу, что если i = 3 и j = 3 => (x1 + x2 = 6/100), то вызывается оператор else, что, конечно, не должно выполняться как 6/100 <1. I Я, наверное, очень плотный, но любая помощь будет оценена. </p>
Спасибо.
EDIT//
Here are the logs I am getting:
Thanks for your comments, here is the log:
0.023799999999999998
arbitrage.js:49 (3) [0.98, 0.01, 0.01]
arbitrage.js:48 0.034
arbitrage.js:49 (3) [0.97, 0.02, 0.01]
arbitrage.js:48 0.047599999999999996
arbitrage.js:49 (3) [0.96, 0.02, 0.02] //point A
arbitrage.js:53 Hello
arbitrage.js:54 0.047599999999999996
arbitrage.js:55 (3) [0.96, 0.02, 0.02] //point B
arbitrage.js:48 0.068
arbitrage.js:49 (3) [0.95, 0.03, 0.02]
arbitrage.js:48 0.07139999999999999
arbitrage.js:49 (3) [0.94, 0.03, 0.03] //point A
arbitrage.js:53 Hello
arbitrage.js:54 0.07139999999999999
arbitrage.js:55 (3) [0.94, 0.03, 0.03] //point B
arbitrage.js:48 0.09519999999999999
arbitrage.js:49 (3) [0.9299999999999999, 0.04, 0.03] //point A
arbitrage.js:53 Hello
arbitrage.js:54 0.09519999999999999
arbitrage.js:55 (3) [0.9299999999999999, 0.04, 0.03] //point B
If you look at Point A which has run through the normal if statement and then look at point B which has run through the else statement. The values for x2,x3 and hence x1 are the same. How can this run through both if and else? Also none of these should run through point B as 0.02+0.02 for example < 1.
//
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;
}