@koodu-platform/formula
v0.1.0
Published
Simply, Evaulate Formulas in JavaScript
Readme
Formula Evaluation
Simply, Evaulate Formulas in JavaScript
Installation
npm install @koodu-platform/formulaUsage
Create a new instance of the
Formulaclass 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, wherea,b,c,d, etc. are coefficients,xis the variable, andnis the degree of the polynomial.Call the
callmethod on theFormulainstance, passing the values of the variables as arguments:const result = formula(2);The
callmethod evaluates the polynomial formula with the provided variable values and returns the result.Note: The number of arguments passed to the
callmethod must match the number of variables specified when creating theFormulainstance. Otherwise, an error will be thrown.Handle the result returned by the
callmethod:console.log(result); // Output: 55The result is the evaluated value of the polynomial formula with the given variable values.
License
see LICENSE for more details.
