Skip to content

alg-js/bisect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@alg/bisect

JSR API License

A generic binary search implementation.

Install

deno add jsr:@alg/bisect

Example

import {bisect} from "@alg/sequences";

const arr = [-1, 2, 2, 4, 5];

console.log(bisect(arr, -2));  // 0
console.log(bisect(arr, 2));  // 1
console.log(bisect(arr, 3));  // 3
console.log(bisect(arr, 6));  // 5

A function defining the < relation can be given to define the ordering of items.

import {bisect} from "@alg/sequences";

const strings = ["a", "abc", "abcd"];
const lt = (a, b) => a.length < b.length

console.log(bisect(strings, "ab", lt));  // 1

About

A generic binary search implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published