Options
All
  • Public
  • Public/Protected
  • All
Menu

sortedindex

build npm version

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

sortedindex は二分探索を行う関数が入った npm パッケージです。

Usage / 使い方

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

const i1 = sortedIndex([1, 2, 4, 5], 3); // 2
const i2 = sortedIndex(["a", "b", "d", "e"], "c", (o) => o.charCodeAt(0)); // 2

Credits / 開発者


Copyright (c) 2021 Jun Kato

Index

Functions

Functions

sortedIndex

  • sortedIndex<T>(array: T[], obj: T | number, accessor?: (obj: T) => number): number
  • 二分探索 / Binary search

    Type parameters

    • T

    Parameters

    • array: T[]

      順序付き配列 / Sorted array of objects

    • obj: T | number

      配列中のインデックスを探索するオブジェクト / Object to find an appropriate index

    • Optional accessor: (obj: T) => number

      オブジェクトの数値表現を返す関数 / Accessor function that returns numeric representation of the object

        • (obj: T): number
        • Parameters

          • obj: T

          Returns number

    Returns number

    オブジェクトを挿入すべき位置のインデックス / An appropriate index value in the sorted array to insert the object

Legend

Generated using TypeDoc