array-helper-utils
is a Node.js utility package designed to simplify common array operations. This package provides helper methods for tasks such as finding sums, removing duplicates, counting occurrences, sorting, and more.
Install the package using npm:
npm install array-helper-utils
Import the ArrayHelper
class and initialize it with an array to perform various operations.
const ArrayHelper = require('array-helper-utils');
const numbers = [2, 4, 6, 2, 8, 6, 10];
const helper = new ArrayHelper(numbers);
console.log("Sum:", helper.getSum());
console.log("Unique elements:", helper.removeDuplicates());
console.log("Product:", helper.getProduct());
console.log("Max:", helper.findMax());
console.log("Min:", helper.findMin());
console.log("Occurrences:", helper.countOccurrences());
console.log("All Even:", helper.allEven());
console.log("Divisible by 2:", helper.divisibleBy(2));
console.log("Sorted Ascending:", helper.sortAscending());
console.log("Reversed:", helper.reverseArray());
Returns the sum of all elements in the array.
Removes duplicate elements from the array and returns a new array.
Returns the product of all elements in the array.
Finds and returns the largest number in the array.
Finds and returns the smallest number in the array.
Returns an object representing the count of each element in the array.
Checks if all elements in the array are even. Returns true
or false
.
Finds all numbers in the array divisible by the specified number n
.
Sorts the array in ascending order and returns the sorted array.
Reverses the array and returns the reversed array.
- Easy-to-use utility methods for array manipulation.
- Handles edge cases like empty arrays and invalid input.
- Fully modular and customizable for various use cases.
This project is licensed under the MIT License. See the LICENSE file for details.
Yash Mankar
Start simplifying your array operations with array-helper-utils
!