ruby and js binary search