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).parseIntconverts the first argument (in this case anumber) to astringbefore parsing it.Given that you chose to use
parseInt(), not specifying theradixis risky. Basically in your caseradixwasundefinedso JavaScript looks at the beginning of the first argument to figure out what radix to use. You lucked out but given that you know theradixyou should useparseInt((start + end)/2, 10)instead (though I'm still voting forMath.floor(),Math.trunc()).Looks great. Thanks for your suggestion…