utility-functions-library
v1.0.1
Published
A utility library for HCF calculation, removing duplicates, and more.
Downloads
137
Maintainers
Readme
Utility Functions Library
This library provides a collection of utility functions for array operations, string manipulation, and other common programming tasks. Each function is designed to be reusable, efficient, and easy to integrate into your projects.
Installation
Install the package via NPM:
npm install utility-functions-library
Features
removeDuplicates
Removes duplicate elements from an array.
arraySum
Calculates the sum of all numbers in an array.
capitalizeString
Capitalizes the first letter of each word in a string.
getUniqueElements
Returns unique elements from an array, maintaining their first occurrence order.
findUnion
Finds the union of multiple arrays.
chunkArray
Splits an array into smaller chunks of a specified size.
Usage
Import the functions into your project:
const {
removeDuplicates,
arraySum,
capitalizeString,
getUniqueElements,
findUnion,
chunkArray,
} = require("utility-functions-library");
Examples
Remove Duplicates
const numbers = [1, 2, 2, 3, 4, 4, 5]; console.log(removeDuplicates(numbers)); // Output: [1, 2, 3, 4, 5]
Calculate Array Sum
const numbers = [10, 20, 30, 40]; console.log(arraySum(numbers)); // Output: 100
Capitalize String
const sentence = "hello world from javascript!"; console.log(capitalizeString(sentence)); // Output: "Hello World From Javascript!"
Get Unique Elements
const items = [5, 1, 3, 5, 2, 3, 6]; console.log(getUniqueElements(items)); // Output: [5, 1, 3, 2, 6]
Find Union
const array1 = [1, 2, 3]; const array2 = [3, 4, 5]; const array3 = [5, 6, 7]; console.log(findUnion(array1, array2, array3)); // Output: [1, 2, 3, 4, 5, 6, 7]
Chunk Array
const numbers = [1, 2, 3, 4, 5, 6, 7]; console.log(chunkArray(numbers, 3)); // Output: [[1, 2, 3], [4, 5, 6], [7]]