I am converting c++ code into javascript that is here. The rest of the code looks fine but following function has a problem. First, second line inside while loop throws error Uncaught ReferenceError: Invalid left-hand side in assignment
. When I change that to m = (A[m] >= key ? r : l);
then this loop becomes infinite. How can I solve it in javascript?
function CeilIndex(A, l, r, key) {
var m;
while( r - l > 1 ) {
m = l + (r - l)/2;
(A[m] >= key ? r : l) = m; // ternary expression returns an l-value
}
return r;
}