1.0.1 • Published 6 years ago

value-index-pair-interface v1.0.1

Weekly downloads
10
License
FREE
Repository
-
Last release
6 years ago

To include in your project:

import { IValueIndexPair } from 'value-index-pair-interface/IValueIndexPair';

This is an interface for an object representing a single array item:

export interface IValueIndexPair {
    value: any;
    index: number; // integer
}

Usage Example:

You need to extract some items from an array. But not only do you need the values,
you need their indexes too, so you write this function, specifying that it returns
an array of IValueIndexPairs:

function getValueAndIndex(  
    testFunction(item, index?, array?) => boolean,  
    array  
): IValueIndexPair[]

This lets everyone know it will return an array looking something like this:

[
	{value: 'some text', index: 5},  
	{value: 10, index: 15},  
	{value: false, index: 33}  
	...more items...
]