if its triangle javascript whats wrong

Back to Problem Solutions forum

not44kcal     2019-11-17 11:31:54
function isTriangle(arrAline, arrBline, arrCline) {
   let result = [];
    for (let i = 0; i < arrAline.length; i++) {
      if (arrAline[i] + arrBline[i] > arrCline[i] && arrAline[i] + arrCline[i] > arrBline[i] && arrCline[i] + arrBline[i] > arrAline[i]) {
        result.push(1);
        } else {
         result.push(0);
            }
             }
              return result;
                 };


let arrAline = [524, 1300, 916, 240, 2186, 250, 1480, 738, 989, 881, 954, 2437, 903, 736, 1474, 1104, 923, 833, 406, 1091];
let arrBline = [395, 502, 614, 377, 1019, 186, 774, 1177, 806, 602, 1297, 1064, 1794, 589, 808, 1236, 467, 393, 779, 2645];
let arrCline = [213, 683, 437, 1126, 683511, 3452, 522, 1896, 1685, 2709, 588, 3159, 1142, 468, 699, 382, 248, 1722, 784];
console.log(isTriangle(arrAline, arrBline, arrCline).join(' '));

//a + b > c //a + c > b //c + b > a

Could any1 tell me why my answeres from this code are wrong ?

Also, what is the best way to copy and past input data (javascript) from the website becasue adding comas/editing 300 random numbers its not fun.

Thanks,

Rodion (admin)     2020-01-03 13:19:18
User avatar

Could any1 tell me why my answeres from this code are wrong

Not sure, but you probably miss zero-area triangles.

becasue adding comas/editing 300 random numbers

you are programmer, try doing this in your program - e.g. split line by spaces, convert to array etc... :)

Please login and solve 5 problems to be able to post at forum