Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solveQuadraticEquation(a, b, c) {
- let d = getDiscriminant(a, b, c);
- if (b === 0 && c === 0) {
- console.log(0);
- return;
- }
- if (d < 0) {
- console.log("No");
- return;
- }
- let roots = getRoots(a, b, d);
- for (let root of roots.filter((v, i, f) => f.indexOf(v) === i).sort()) {
- console.log(root);
- }
- function getRoots(aa, bb, dd) {
- let result = [];
- result.push((-bb - Math.sqrt(dd)) / (2 * aa));
- result.push((-bb + Math.sqrt(dd)) / (2 * aa));
- return result;
- }
- function getDiscriminant(a, b, c) {
- return (b ** 2 - 4 * a * c);
- }
- }
- //solveQuadraticEquation(6, 11, - 35);
- //solveQuadraticEquation(1, - 12, 36);
- //solveQuadraticEquation(5, 2, 1);
- solveQuadraticEquation(-4, 3, 4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement