Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. function solve([a, b, c]) {
  2. [a, b, c] = [a, b, c].map(Number);
  3.  
  4. let d = ((Math.pow(b, 2)) - (4 * a * c));
  5. let x1 = (-b + Math.sqrt(d)) / (2 * a);
  6. let x2 = (-b - Math.sqrt(d)) / (2 * a);
  7.  
  8. if (d > 0 && x1 < x2) {
  9. console.log(x1 + "\n" + x2);
  10. }
  11. else if (d > 0 && x2 < x1) {
  12. console.log(x2 + "\n" + x1);
  13. }
  14. else if (d == 0) {
  15. console.log(x1);
  16. }
  17. else if (d < 0) {
  18. console.log("no");
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement