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 (d === 0) {
- let x = -(b / (2 * a));
- console.log(x);
- return;
- }
- if (d < 0) {
- console.log("No");
- return;
- }
- let roots = getRoots(a, b, d);
- console.log(roots.join(' '));
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement