SHARE
TWEET

Untitled

ambiorixdr Jan 19th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solveQuadraticEquation(a, b, c) {
  2.  
  3.     let d = getDiscriminant(a, b, c);
  4.  
  5.     if (d === 0) {
  6.  
  7.         let x = -(b / (2 * a));
  8.         console.log(x);
  9.         return;
  10.     }
  11.  
  12.     if (d < 0) {
  13.         console.log("No");
  14.         return;
  15.     }
  16.  
  17.     let roots = getRoots(a, b, d);
  18.  
  19.     console.log(roots.join(' '));
  20.  
  21.     function getRoots(aa, bb, dd) {
  22.         let result = [];
  23.  
  24.         result.push((-bb - Math.sqrt(dd)) / (2 * aa));
  25.         result.push((-bb + Math.sqrt(dd)) / (2 * aa));
  26.  
  27.         return result;
  28.     }
  29.  
  30.     function getDiscriminant(a, b, c) {
  31.         return (b ** 2 - 4 * a * c);
  32.     }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top