A TypeScript/JavaScript utility library for modern and efficient array operations.
npm install arrays-tool
import { ArrayUtils } from 'arrays-tool';
// Example array
const numbers = [1, 2, 3, 4, 5];
// Shuffle array
const shuffled = ArrayUtils.shuffle(numbers);
console.log(shuffled); // [3, 1, 5, 2, 4]
// Reverse array
const reversed = ArrayUtils.reverse(numbers);
console.log(reversed); // [5, 4, 3, 2, 1]
// Get random element
const random = ArrayUtils.random(numbers);
console.log(random); // 3
// Remove duplicates
const withDuplicates = [1, 2, 2, 3, 3, 4];
const unique = ArrayUtils.unique(withDuplicates);
console.log(unique); // [1, 2, 3, 4]
// Merge arrays
const array1 = [1, 2, 3];
const array2 = [3, 4, 5];
const merged = ArrayUtils.merge(array1, array2);
console.log(merged); // [1, 2, 3, 4, 5]
import { ArrayUtils } from 'arrays-tool';
const numbers = [1, 2, 3, 4, 5];
// Calculate sum
const sum = ArrayUtils.sum(numbers);
console.log(sum); // 15
// Calculate average
const avg = ArrayUtils.average(numbers);
console.log(avg); // 3
// Find maximum
const max = ArrayUtils.max(numbers);
console.log(max); // 5
// Find minimum
const min = ArrayUtils.min(numbers);
console.log(min); // 1
// Calculate product
const product = ArrayUtils.product(numbers);
console.log(product); // 120
- 📦 Zero dependencies
- 💪 TypeScript support
- 🚀 High performance
- 🎯 Tree-shaking support
- 📝 Comprehensive documentation
Shuffles the array and returns a new array.
Reverses the array and returns a new array.
Selects and returns a random element from the array.
Removes duplicate elements and returns a new array.
Merges two arrays and removes duplicate elements.
Calculates the sum of all numbers in the array.
Calculates the average (mean) of all numbers in the array.
Returns the maximum number in the array.
Returns the minimum number in the array.
Calculates the product of all numbers in the array.
MIT © [Adem Hatay]