@288-toolkit/arrays

1.0.1 • Public • Published

Arrays

npm i @288-toolkit/arrays

A collection of functions to work with arrays.

dedupeArray()

Removes duplicates from an array of values (string | number | symbol | boolean).

dedupeArray([1, 2, 2, 2, '4', '5', '4', true, true]); // [1, 2, '4', '5', true]

dedupeArrayOfObjects()

Removes duplicates from an array of objects based on the value of a key.

const people: Person[] = [
	{ id: 1, name: 'John', age: 30 },
	{ id: 2, name: 'Jane', age: 25 },
	{ id: 3, name: 'John', age: 30 },
	{ id: 4, name: 'Alice', age: 35 },
	{ id: 5, name: 'Jane', age: 25 }
];

const uniquePeople = dedupeArrayOfObjects(people, 'name');

// [
//     { id: 1, name: "John", age: 30 },
//     { id: 2, name: "Jane", age: 25 },
//     { id: 4, name: "Alice", age: 35 },
// ]

randomIndex()

Returns a random index from an array with a random uniform distribution. See randomInt

randomItem()

Returns a random item from an array with a random uniform distribution. See randomInt

shuffleArray()

Creates a shuffled copy of an array.

Readme

Keywords

none

Package Sidebar

Install

npm i @288-toolkit/arrays

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

4.92 kB

Total Files

10

Last publish

Collaborators

  • nitriques
  • f-elix