Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function diagonalSums(input) {
- let matrix = [];
- for (let r = 0; r < input.length; r++) {
- let line = input[r].split(',').map(Number);
- matrix.push(line);
- }
- var lenghtLine1 = calculateDistanceBetweenTwoPoints(matrix[0][0], matrix[1][0], matrix[2][0], matrix[3][0]);
- var lenghtLine2 = calculateDistanceBetweenTwoPoints(matrix[4][0], matrix[5][0], matrix[6][0], matrix[7][0]);
- var lenghtLine3 = calculateDistanceBetweenTwoPoints(matrix[8][0], matrix[9][0], matrix[10][0], matrix[11][0]);
- console.log(lenghtLine1.toFixed(2));
- console.log(lenghtLine2.toFixed(2));
- console.log(lenghtLine3.toFixed(2));
- if(canFormTriangle(lenghtLine1,lenghtLine2,lenghtLine3)==true){
- console.log("Triangle can be formed");
- }
- else{
- console.log("Triangle can't be formed");
- }
- function calculateDistanceBetweenTwoPoints(PointOneX, PointOneY, PointTwoX, PointTwoY) {
- return (Math.sqrt(Math.pow(PointTwoX - PointOneX, 2) + Math.pow(PointTwoY - PointOneY, 2)));
- }
- function canFormTriangle(line1, line2, line3) {
- return line1 + line2 > line3 && line2 + line3 > line1 && line3 + line1 > line2;
- }
- }
- diagonalSums([
- '5', '6', '7', '8',
- '1', '2', '3', '4',
- '9', '10', '11', '12'
- ]);
- diagonalSums([
- '7', '7', '2', '2',
- '5', '6', '2', '2',
- '95', '-14.5', '0', '-0.123'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement