Skip to content

Documentation / @ripl/charts / createIndexLookup

Function: createIndexLookup() ​

createIndexLookup<TValue>(values): (value) => number

Defined in: charts/src/core/data.ts:58

Builds a value → index lookup with Array.prototype.indexOf semantics: the earliest occurrence wins for a duplicated value, an absent value resolves to -1, and NaN matches nothing.

A render loop that resolves each datum's position with indexOf is quadratic over a series; building the lookup once makes every resolution constant time.

Type Parameters ​

Type ParameterDescription
TValueThe array's element type.

Parameters ​

ParameterTypeDescription
valuesreadonly TValue[]The array to index, in order.

Returns ​

A function resolving a value to its index in values, or -1 when absent.

(value) => number