Skip to content

Returns the index of the first instance; when called a second time, returns the index of the second instance; and so on. Works with arrays and strings. Packaged as a Node.js module.

License

lamansky/sequential-indexof

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sequential-indexof

Returns the index of the first instance; when called a second time, returns the index of the second instance; and so on. Works with arrays and strings. Packaged as a Node.js module.

Installation

npm install sequential-indexof --save

Usage

const sequentialIndexOf = require('sequential-indexof')

const array = ['a', 'b', 'a']
const indexOf = sequentialIndexOf(array) // returns a function

indexOf('a') // returns 0, the first index of 'a'
indexOf('a') // returns 2, the second index of 'a'
indexOf('a') // returns -1, since there are no more instances of 'a'

indexOf('b') // returns 1, the first index of 'b'
indexOf('b') // returns -1, since there are no more instances of 'b'

indexOf('c') // returns -1, since there are no instances of 'c'

About

Returns the index of the first instance; when called a second time, returns the index of the second instance; and so on. Works with arrays and strings. Packaged as a Node.js module.

Resources

License

Stars

Watchers

Forks

Packages

No packages published