A lightweight package that applies mathematical transformations to arrays using functional programming concepts.
You can install the package using npm:
npm i math-array-transform
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"
}
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.
import { mapWithFunctions } from "math-array-transform";
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 ]