Skip to content

arcatdmz/sortedIndex

Repository files navigation

sortedindex

npm version license

sortedindex is a tiny TypeScript package that uses binary search to find the leftmost insertion index in a sorted array.

sortedindex は、二分探索でソート済み配列に対する左端の挿入位置を返す小さな TypeScript パッケージです。

Usage / 使い方

npm install sortedindex
import { sortedIndex } from "sortedindex";

const i1 = sortedIndex([1, 2, 4, 5], 3); // 2
const i2 = sortedIndex([1, 2, 2, 2, 3], 2); // 1
const i3 = sortedIndex(["a", "b", "d", "e"], "c", (o) => o.charCodeAt(0)); // 2
const i4 = sortedIndex([{ score: 10 }, { score: 20 }, { score: 40 }], 25, (o) => o.score); // 2

Development / 開発

npm test
npm run build

Credits / 開発者


Copyright (c) 2021-2026 Jun Kato

About

A simple npm package that provides a binary search function for a sorted array.

Topics

Resources

License

Stars

Watchers

Forks

Contributors