sorted-indexof
Given two sorted arrays, a and b, efficiently return an array of indexes of b's elements in a.
Last updated 7 years ago by mafintosh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install sorted-indexof 
SYNC missed versions from official npm registry.

sorted-indexof

Given two sorted arrays, a and b, efficiently return an array of indexes of b's elements in a.

Runs in O(n+m) where n and m are the sizes of the sorted arrays.

npm install sorted-indexof

Build Status

Usage

var indexOf = require('sorted-indexof')

var a = ['b', 'c', 'd', 'e', 'f']
var b = ['a', 'b', 'c', 'f', 'g', 'h']

console.log(indexOf(a, b))

Running the above returns

[ -1, 0, 1, 4, -1, -1 ]

Which corresponds to taking each element of b and running a.indexOf(el).

API

var indexes = indexOf(a, b)

Returns an array of indexes of bs elements in a. An an element in b does not exist in a, -1 is inserted.

Note that a and b MUST be sorted.

License

MIT

Current Tags

  • 1.0.0                                ...           latest (7 years ago)

1 Versions

  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |