@writetome51/get-indexes-of-item-duplicates
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

getIndexesOfItemDuplicates(
      value,
      array
): number[]

Returns indexes of every duplicate instance of value in array.
It errors if value is an object, null, undefined, or an array that contains
an object.

Examples

let arr = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4];
getIndexesOfItemDuplicates(1, arr);
// --> [4, 8]

arr = ['aaa', 'a', 'aa', 'aa', 'aaaa', 'a', 'aa'];
getIndexesOfItemDuplicates('a', arr);
// --> [5]

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

arr = [ [1, 2], [1, 2, 'r'], [3, 4], [1, 2, 'r'], [3, 4] ];
getIndexesOfItemDuplicates([1, 2, 'r'], arr);
// --> [3]

// Errors if value is object:
arr = [ {prop: 1}, {prop: 1} ];
getIndexesOfItemDuplicates({prop: 1}, arr);
//  Error: "Input must be either a primitive type or an array"

Installation

npm install @writetome51/get-indexes-of-item-duplicates

Loading

// if using TypeScript:
import { getIndexesOfItemDuplicates } 
    from '@writetome51/get-indexes-of-item-duplicates';
// if using ES5 JavaScript:
var getIndexesOfItemDuplicates = 
    require('@writetome51/get-indexes-of-item-duplicates')
    .getIndexesOfItemDuplicates;

License

MIT

Package Sidebar

Install

npm i @writetome51/get-indexes-of-item-duplicates

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

12.7 kB

Total Files

8

Last publish

Collaborators

  • writetome51