fix stupid error in for loop

This commit is contained in:
David MAECHLER 2020-04-06 01:45:51 +02:00
parent 21d7fb733a
commit 886477cddf

View File

@ -1,7 +1,7 @@
// Constants // Constants
let MIN_DISTANCE = 12; let MIN_DISTANCE = 12;
let MAX_PER_GROUP = 3; let MAX_PER_GROUP = 3;
let NB_USERS = 4; let NB_USERS = 10;
// Utils // Utils
let rand = function(min, max) { let rand = function(min, max) {
@ -34,8 +34,6 @@ for(let i = 1; i <= NB_USERS; i++) {
users.push(user); users.push(user);
} }
console.log(users);
// Compute distance between each user // Compute distance between each user
let getDistanceOfEachUser = function(users) { let getDistanceOfEachUser = function(users) {
let i = 0; let i = 0;
@ -74,7 +72,7 @@ let createGroups = function(distances) {
if(groups[i].indexOf(dist.first) === -1 && typeof alreadyInAGroup[dist.first.id] === 'undefined') { if(groups[i].indexOf(dist.first) === -1 && typeof alreadyInAGroup[dist.first.id] === 'undefined') {
if(groups[i].length > 1) { if(groups[i].length > 1) {
for(let l = 0; groups[i].length; l++) { for(let l = 0; l < groups[i].length; l++) {
let userTotest = groups[i][l]; let userTotest = groups[i][l];
if(computeDistance(dist.first, userTotest) <= MIN_DISTANCE) { if(computeDistance(dist.first, userTotest) <= MIN_DISTANCE) {
groups[i].push(dist.first); groups[i].push(dist.first);
@ -99,7 +97,7 @@ let createGroups = function(distances) {
if(groups[i].indexOf(dist.second) === -1 && typeof alreadyInAGroup[dist.second.id] === 'undefined') { if(groups[i].indexOf(dist.second) === -1 && typeof alreadyInAGroup[dist.second.id] === 'undefined') {
if(groups[i].length > 1) { if(groups[i].length > 1) {
for(let l = 0; groups[i].length; l++) { for(let l = 0; l < groups[i].length; l++) {
let userTotest = groups[i][l]; let userTotest = groups[i][l];
if(computeDistance(dist.second, userTotest) <= MIN_DISTANCE) { if(computeDistance(dist.second, userTotest) <= MIN_DISTANCE) {
groups[i].push(dist.second); groups[i].push(dist.second);
@ -127,6 +125,7 @@ let groups = createGroups(distances);
// TODO : Créer une méthode pour checker la distance entre les membres du groupes pour savoir s'il faut les dissoudre ou non // TODO : Créer une méthode pour checker la distance entre les membres du groupes pour savoir s'il faut les dissoudre ou non
console.log(users);
console.log(distances); console.log(distances);
console.log(groups); console.log(groups);