tiny-array-utils
v1.0.0
Published
A lightweight, zero-dependency library for common array manipulations.
Downloads
154
Maintainers
Readme
tiny-array-utils
A lightweight, zero-dependency library for common array manipulations.
Installation
npm install tiny-array-utilsUsage
import { chunk, shuffle, unique, range, groupBy } from 'tiny-array-utils';
chunk([1,2,3,4,5], 2); // [[1,2],[3,4],[5]]
unique([1,1,2,3,3]); // [1,2,3]
range(0, 5); // [0,1,2,3,4]Available Functions
chunk(arr, size)— Split array into chunksshuffle(arr)— Shuffle array (Fisher-Yates)unique(arr)— Remove duplicatesflatten(arr, depth?)— Flatten nested arrayslast(arr)/first(arr)— Get last/first elementsample(arr)— Random elementzip(...arrays)— Zip arrays togetherrange(start, end, step?)— Generate number rangegroupBy(arr, fn)— Group by key functionintersection(a, b)— Common elementsdifference(a, b)— Elements in a but not in b
