Skip to content

CharlotteGore/binary-search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

binary-search

A binary search algorithm for finding values in sorted arrays.

Installation

Browserify/npm

    $ npm install --save gm-binary-search
  var search = require('gm-binary-search');

Component

    $ component install charlottegore/binary-search
  var search = require('binary-seach');

API

Takes an array and a target to search for

> var arr = [1,2,3,4,6,7,8];
> require('binary-search')(arr, 3);
> [2, true]

When the target is found, it returns the index of the target and 'true'.

> require('binary-search')(arr, 5);
> [4, false]

When the target isn't found, it returns the index the target value could be inserted at and 'false'.

License

MIT

About

Binary search algorithm that returns possible entry point on failure

Resources

Stars

Watchers

Forks

Packages

No packages published