내 Javscript 기능이 브라우저를 계속 충돌시킵니다. 그것이 충돌 할 때가 거의 없지만, 당신은 그 때가 있습니다. 파이어 버그를 사용하면 모든 것을 망가 뜨리는 while 회 돌이처럼 보입니다. 누구든지 어떤 생각을 가지고 있습니까? 우선While 루프가 브라우저를 닫습니다.
function generateTeams(pos = 0) {
// Array of ID's
var currentTeams = [];
// 2D array with matches and teamIds
var matches = [];
$.each($teamList, function() {
// Push integer into a new array
if (this.position >= pos) currentTeams.push(this.id);
});
// NumberOfTeams is ALWAYS even numbers, and can be divided by 2
var numberOfTeams = currentTeams.length;
var numberOfMatches = numberOfTeams/2;
if ((numberOfTeams > 2) && (numberOfTeams % 2 == 0)) {
var currentCount = numberOfTeams;
for (var i = 0; i < numberOfMatches; i++) {
var numOne = Math.floor(Math.random() * currentCount);
var numTwo = Math.floor(Math.random() * currentCount);
// Checks if the numbers are the same, or if two spesific teams is against each-other.
while ((numOne == numTwo) || (currentTeams[numOne] == 1 && currentTeams[numTwo] == 3) || (currentTeams[numOne] == 3 && currentTeams[numTwo] == 1)) {
numTwo = Math.floor(Math.random() * currentCount);
}
// Creates a match-array with the two team ID's
matches.push([parseInt(currentTeams[numOne]), parseInt(currentTeams[numTwo])]);
// Simple way to remove them from the start-array.
if (numOne > numTwo) {
currentTeams.splice(numOne, 1);
currentTeams.splice(numTwo, 1);
} else {
currentTeams.splice(numTwo, 1);
currentTeams.splice(numOne, 1);
}
currentCount -= 2;
} // End for-loop
} else {
matches.push([parseInt(currentTeams[0]), parseInt(currentTeams[1])]);
} // End if
currentMatches = matches;
} // End generateTeams
while 루프의 맨 위에있는 조건은 루프 내부에서 아무런 문제없이 유지된다는 것을 의미합니다. 관련된 값을 추적하기 위해'console.log()'호출을 추가 할 수 있습니다. – Pointy