1.0.3 • Published 7 years ago

indexes-of-sequence v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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

npm install indexes-of-sequence

bower

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

Copyright (c) 2016 Shinnosuke Watanabe

Licensed under the MIT License.