You are viewing a single comment's thread. Return to all comments →
Awesome. To make the code reuseable in cases where x2 isn't guaranteed to be greater than x1, i made some changes; Before the while loop, i added this
var sign = x2 - x1; `if (sign > 0) { sign = -1 } else { sign = 1 }`
var sign = x2 - x1;
`if (sign > 0) { sign = -1 } else { sign = 1 }`
I then included this sign into the while loop:
while (Math.sign(difference) != sign) {...do your logic...}
while (Math.sign(difference) != sign)
{...do your logic...}
Seems like cookies are disabled on this browser, please enable them to open this website
Number Line Jumps
You are viewing a single comment's thread. Return to all comments →
Awesome. To make the code reuseable in cases where x2 isn't guaranteed to be greater than x1, i made some changes; Before the while loop, i added this
I then included this sign into the while loop: