index-of-sequence

1.0.0 • Public • Published

index-of-sequence

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

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']); //=> 2

Installation

npm

npm install index-of-sequence

bower

bower install index-of-sequence

API

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); //=> 7

Otherwise, it returns -1.

indexOfSequence([], [4]); //=> -1
indexOfSequence([1, 2, 3], [4]); //=> -1
indexOfSequence([1, 2, 3], []); //=> -1

License

Copyright (c) 2016 Shinnosuke Watanabe

Licensed under the MIT License.

/index-of-sequence/

    Package Sidebar

    Install

    npm i index-of-sequence

    Weekly Downloads

    2

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • shinnn