The JavaScript function for solving a quadratic equation.
$ npm install quadratic-roots-function
import {solveEquation} from 'quadratic-roots-function';
solveEquation(1, -3, -4);
// [4.0, -1.0]
solveEquation(1, 2, 1);
// [-1.0]
solveEquation(2, 4, 6);
// []
import {solveEquation} from 'quadratic-roots-function';
solveEquation(a, b, c);
Parameter | Type | Required | Description |
---|---|---|---|
a | Number | Yes | The quadratic coefficient |
b | Number | Yes | The linear coefficient |
c | Number | Yes | The constant |
- when both roots are real, returns an array with two roots;
- when only one root is real, returns an array with one root;
- when both roots are imaginary, returns an empty array.