soldair / node-binarysearch

binary search for sorted javascript arrays||array like obejcts. provides method to create sorted index of objects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

returning 1 when should not.

bryanrasmussen opened this issue · comments

this bs(["a","b","cde","f"],"wtf") returns 1.
this
bs([1,2,3,4],"wtf");
also returns 1.
obviously the second one is a data type problem, probably should just check to see that it is the same data type coming in and fail if not.

The first one I suppose is that an array of sorted numerical datatypes are expected, but that seems messed up since binary search can be used with sorted string arrays also.

its been a while but i think you need to pass in your own comparator to handle string values/mixed type values.
ill take a look though =)

hi, you're right of course, but I think there should be some sort of
warning popping up. especially in cases of type mismatch.

I did get it working with my own comparator.

Thanks,
Bryan Rasmussen

On Wed, Mar 9, 2016 at 2:26 PM, Ryan Day notifications@github.com wrote:

its been a while but i think you need to pass in your own comparator to
handle string values/mixed type values.
ill take a look though =)


Reply to this email directly or view it on GitHub
#6 (comment)
.

i decided to add support for mixed types in the default comparator. ill bump the major version just in case as it might break folks.

published as version v1.0.0 added test in test/strings.js