Skip to content

Optimize bsearchIndex method #70

@kiellabian

Description

@kiellabian

Currently, the bsearchIndex method is using slice, which creates a partial, shallow copy of the original array into a new array -- meaning it uses extra memory. This extra memory is unnecessary and will scale when handling large arrays. We can avoid this with simple manipulation of the starting and ending indexes ("i" and "j", respectively).

Moreover, instead of using recursion, this can be done with a loop which is actually more efficient.

Lastly, it will be helpful if this phrase is added in the docs:
Use bsearchIndex or bsearch on arrays, assuming it is already sorted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions