You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sudipto Ghosh 000cb67518 changed linting options 4 months ago
dist added function definitions 5 months ago
lib added function definitions 5 months ago
src added function definitions 5 months ago
.babelrc changed to es6 module with backwards comptability, 6 months ago
.drone.yml updated .drone.yml again 6 months ago
.eslintignore revamp directory structure, improved linting and transpiling 6 months ago
.eslintrc changed linting options 4 months ago
.gitignore Revert "sepeare cjs modules using babel" 6 months ago
.travis.yml added support for travis 6 months ago
LICENSE.md initial commit 6 months ago
README.md fixed travis link 6 months ago
package-lock.json added MatrixSolver class, renamed functions to camelcase 6 months ago
package.json added function definitions 5 months ago
webpack.config.js revamp directory structure, improved linting and transpiling 6 months ago

README.md

Quadratic Equation Solver

npm Drone Status Travis Status Codecov Dependencies

This JavaScript library-slash-module brings the ability of finding roots of a quadratic equation by simply requiring it :)

Example Usage

Browser Import

<script src="https://unpkg.com/quadratic-solver"></script>
<script>
    console.log(qs.getVersion());
    const rootsArr = qs.quadSolver(2, 5, -3);
    rootsArr.map(root => console.log(`Root: ${root}`));
</script>

NodeJS Module

const { quadSolver, getVersion } = require("quadratic-solver");
console.log(getVersion());
const rootsArr = quadSolver(2, 5, -3);
rootsArr.map(root => console.log(`Root: ${root}`));

Methods

quadSolver(a, b, c)

Arguments

  • a: coefficent of the squared term.
  • b: coefficient of the linear term.
  • c: constant with its sign.

Return Value

  • when both roots are real: Array[2] with the roots of the equation.
  • when only one root is real: Array[2] wherein the first element is the real root and the other element is a warning.
  • when both roots are imaginary: Array[2] in which both elements are warnings.

Note: If a is equal to 0, quadSolverCitardauq() will be called automatically with the arguments as provided.

completeSquare(a, b, c)

Arguments

  • a: coefficent of the squared term.
  • b: coefficient of the linear term.
  • c: constant with its sign.

Return Value

  • when both roots are real: Array[2] with the solutions for the equation.
  • when both roots are imaginary: Array[2] with both elements are in which both elements are NaN.

quadSolverCitardauq(a, b, c)

Arguments

Same as quadSolver(a, b, c).

Return Value

Same as quadSolver(a, b, c).

getVersion()

Arguments

No arguments are required.

Return Value

String containing name and version of the package in quadratic-solver v0.x.x format.

ES6 Classes

Solver(a, b, c)

Properties

  • a: coefficent of the squared term; default: 2.
  • b: coefficient of the linear term; default: 5.
  • c: constant with its sign; default: -3.

Methods

  • solve(): returns output of quadSolver() with properties of the instance.
  • completeSquare(): returns output of completeSquare() with properties of the instance.
  • versionMethod(): returns the output of getVersion().

MatrixSolver([[a, b, c], [d, e, f], …])

Properties

  • matrix: array of arrays containing the coefficients of the quadratic and linear terms, followed by the constant (in that order); default: [[2, 5, -3]].

Methods

  • solveAll(): returns output of quadSolver() for each array in an array of arrays.
  • completeSquareAll(): returns output of completeSquare() for each array in an array of arrays.
  • versionMethod(): returns the output of getVersion().

Author

Sudipto Ghosh sudipto(at)ghosh(dot)pro

License

Source code distributed under the MIT License.