Advertisement
fbinnzhivko

Untitled

Jan 10th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function diagonalSums(input) {
  2.     let matrix = [];
  3.     for (let r = 0; r < input.length; r++) {
  4.         let line = input[r].split(',').map(Number);
  5.         matrix.push(line);
  6.     }
  7.     var lenghtLine1 = calculateDistanceBetweenTwoPoints(matrix[0][0], matrix[1][0], matrix[2][0], matrix[3][0]);
  8.     var lenghtLine2 = calculateDistanceBetweenTwoPoints(matrix[4][0], matrix[5][0], matrix[6][0], matrix[7][0]);
  9.     var lenghtLine3 = calculateDistanceBetweenTwoPoints(matrix[8][0], matrix[9][0], matrix[10][0], matrix[11][0]);
  10.     console.log(lenghtLine1.toFixed(2));
  11.     console.log(lenghtLine2.toFixed(2));
  12.     console.log(lenghtLine3.toFixed(2));
  13.  
  14.  
  15.     if(canFormTriangle(lenghtLine1,lenghtLine2,lenghtLine3)==true){
  16.         console.log("Triangle can be formed");
  17.     }
  18.     else{
  19.         console.log("Triangle can't be formed");
  20.     }
  21.     function calculateDistanceBetweenTwoPoints(PointOneX, PointOneY, PointTwoX, PointTwoY) {
  22.         return (Math.sqrt(Math.pow(PointTwoX - PointOneX, 2) + Math.pow(PointTwoY - PointOneY, 2)));
  23.     }
  24.     function canFormTriangle(line1, line2, line3) {
  25.         return line1 + line2 > line3 && line2 + line3 > line1 && line3 + line1 > line2;
  26.     }
  27. }
  28.  
  29. diagonalSums([
  30.     '5', '6', '7', '8',
  31.     '1', '2', '3', '4',
  32.     '9', '10', '11', '12'
  33. ]);
  34. diagonalSums([
  35.     '7', '7', '2', '2',
  36.     '5', '6', '2', '2',
  37.     '95', '-14.5', '0', '-0.123'
  38. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement