1.0.0 • Published 9 years ago
index-of-sequence v1.0.0
index-of-sequence
Find the first index at which a given sequence of elements can be found in the array
import indexOfSequence from 'index-of-sequence';
indexOfSequence(['a', 'b', 'a', 'b', 'c', 'a', 'b', 'c'], ['a', 'b', 'c']); //=> 2Installation
npm
npm install index-of-sequencebower
bower install index-of-sequenceAPI
indexOfSequence(array, searchArray , fromIndex)
array: Array
searchArray: Array (the sequence of values to search for)
fromIndex: Number (index in the string where to begin searching)
Return: Number (the first index of the sequence of values)
It returns 0 or a positive integer (1, 2, ...) when it finds at least one sequence of values in the array.
indexOfSequence([1, '1', true, '1', 1, Buffer.from('1'), '1', 1, '1'], [1, '1']); //=> 0
indexOfSequence([1, '1', true, '1', 1, Buffer.from('1'), '1', 1, '1'], [1, '1'], 1); //=> 7Otherwise, it returns -1.
indexOfSequence([], [4]); //=> -1
indexOfSequence([1, 2, 3], [4]); //=> -1
indexOfSequence([1, 2, 3], []); //=> -1License
Copyright (c) 2016 Shinnosuke Watanabe
Licensed under the MIT License.