Given that you chose to use parseInt(), not specifying the radix is risky. Basically in your case radix was undefined so JavaScript looks at the beginning of the first argument to figure out what radix to use. You lucked out but given that you know the radix you should use parseInt((start + end)/2, 10) instead (though I'm still voting for Math.floor(), Math.trunc()).
Seems a peculiar use of
parseInt(string, radix)
. I would have expectedMath.floor(number)
orMath.trunc(number)
.parseInt
converts the first argument (in this case anumber
) to astring
before parsing it.Given that you chose to use
parseInt()
, not specifying theradix
is risky. Basically in your caseradix
wasundefined
so JavaScript looks at the beginning of the first argument to figure out what radix to use. You lucked out but given that you know theradix
you should useparseInt((start + end)/2, 10)
instead (though I'm still voting forMath.floor()
,Math.trunc()
).Looks great. Thanks for your suggestion…