@koodu-platform/formula

0.1.0 • Public • Published

Formula Evaluation

Simply, Evaulate Formulas in JavaScript

Installation

npm install @koodu-platform/formula

Usage

  1. Create a new instance of the Formula class by passing the polynomial formula as a string and an optional array of variables:

    const formula = new Formula('3x^2 + 2x - 1', ['x']);

    The formula should be a valid polynomial expression in the form of ax^n + bx^(n-1) + ... + cx + d, where a, b, c, d, etc. are coefficients, x is the variable, and n is the degree of the polynomial.

  2. Call the call method on the Formula instance, passing the values of the variables as arguments:

    const result = formula(2);

    The call method evaluates the polynomial formula with the provided variable values and returns the result.

    Note: The number of arguments passed to the call method must match the number of variables specified when creating the Formula instance. Otherwise, an error will be thrown.

  3. Handle the result returned by the call method:

    console.log(result); // Output: 55

    The result is the evaluated value of the polynomial formula with the given variable values.

License

see LICENSE for more details.

Readme

Keywords

none

Package Sidebar

Install

npm i @koodu-platform/formula

Weekly Downloads

1

Version

0.1.0

License

ISC

Unpacked Size

4.99 kB

Total Files

5

Last publish

Collaborators

  • koodu-platform