Skip to content

shinnn/indexes-of-sequence

Repository files navigation

indexes-of-sequence

NPM version Bower version Build Status Coverage Status dependencies Status devDependencies Status

Find all indexes at which a given sequence of elements can be found in the array

import indexesOfSequence from 'indexes-of-sequence';

indexOfSequence(['a', 'b', 'a', 'b', 'c', 'd', 'a', 'b', 'c'], ['a', 'b', 'c']); //=> [2, 6]

Installation

npm install indexes-of-sequence
bower install indexes-of-sequence

API

indexesOfSequence(array, searchArray [, fromIndex])

array: Array
searchArray: Array (the sequence of values to search for)
fromIndex: Number (index in the array where to begin searching)
Return: Array of Number (indexes of the sequence of values)

indexOfSequence([1, '1', true, '1', 1, Buffer.from('1'), '1', 1, '1'], [1, '1']); //=> [0, 7]
indexOfSequence([1, '1', true, '1', 1, Buffer.from('1'), '1', 1, '1'], [1, '1'], 1); //=> [7]

indexOfSequence(['a'], ['b']); //=> []
indexOfSequence(['a'], []); //=> []
indexOfSequence([], ['b']); //=> []

Related project

index-of-sequence - Find the first index instead

License

Creative Commons Zero v1.0 Universal

About

Find all indexes at which a given sequence of elements can be found in the array

Resources

Stars

Watchers

Forks

Packages

No packages published