What's the matter (Euler Problem 39)?

The task here.

And here is my implementation.
isTraingle function(a, b, c) {
 if( a*a + b*b == c*c) {
 return true;
}
 return false;
}
var traingles = [];

for (var i = 1; i < 998 ; i++) {
 for (var j = 1; j < 998; j++) {
 for (var k = 1; k < 998; k++) {
 var p = i + j + k;
 if(isTraingle(i, j, k)) {
 if(traingles[p]) {
 var flag = true;
 for (var q = 0; q < traingles[p].length; q++) {
 var arr = traingles[p][q];
 if( arr.indexOf(i) >= 0 && arr.indexOf(j) >= 0 && arr.indexOf(k) >= 0) {
 flag = false
break;
 } 
}
 if( flag ) {
traingles[p].push([i,j,k]);
}
 } else {
 traingles[p] = [[i,j,k]];
}
}
}
}
}

var max = 0;
var perimetr = 0;
traingles.forEach(function(el) {
 if(el.length > max) {
 max = el.length;
 perimetr = el[0][0] + el[0][1] + el[0][2];
}
})

console.log(traingles, max, perimetr);


A little googling found the answer, the answer is p = 840;
In my case, out of 1680.
June 14th 19 at 20:14
2 answers
June 14th 19 at 20:16
What significance p ≤ 1000 gives the maximum number of solutions?


Upd:
if( arr.indexOf(i) >= 0 && arr.indexOf(j) >= 0 && arr.indexOf(k) >= 0) {
 flag = false
break;
}

This proverka seem weak. If the array is, for example, [8,7,6], the algorithm considers that the triangle [6,6,8] was already
Do not understand, it can be a little specific? - norene29 commented on June 14th 19 at 20:19
about what exactly?
The clause says that it is necessary to search among the triangles with p<=1000, and you answer write p = 1680

The test decision is not affected, because there is no right isosceles triangles - beatrice_Hamill1 commented on June 14th 19 at 20:22
June 14th 19 at 20:18
You seem to have duplicate options ie:
20,48,52 == 48,20,52
It is one and the same triangle, but rotated.

Find more questions by tags JavaScript