math-array-transform
v1.0.2
Published
This package provides a convenient and useful tool for applying mathematical transformations to arrays using your JavaScript code. The package allows users to apply user-defined mathematical functions to each element of an array, returning the results as
Downloads
3
Maintainers
Readme
math-array-transform
A lightweight package that applies mathematical transformations to arrays using functional programming concepts.
Installation
You can install the package using npm:
npm i math-array-transform
Initialization
To use math-array-transform
with ESM (ECMAScript Modules), you need to add the following configuration to your package.json
file:
// package.json
{
"type": "module"
}
Function
Applies a series of mathematical transformations to each element of the input array.
mapWithFunctions(arr, functionsArray);
- arr: The input array.
- functionsArray: An array of mathematical functions to apply to each element of the input array.
Usage
import { mapWithFunctions } from "math-array-transform";
Example
const arr = [1, 2, 3, 4, 5];
const FunctionsArray = [(n) => Math.pow(n, 2), (n) => Math.sqrt(n), (n) => Math.pow(n, 3)];
const resultArray = mapWithFunctions(arr, FunctionsArray);
console.log(resultArray); // [ 1, 8, 27, 64, 125 ]