I have function that reads a csv file and calculates the distance between two types of values "Client" and "Helper"
function readCSV(e){
var file = e.target.files[0];
var helferList =[];
var kundenList =[];
if (!file) {
console.log('file could not be read');
return;
}
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
var result = $.csv.toArrays(contents);
$('.output').append(",");
for(i = 0; i< result.length; i++){
if(result[i][0] =="Kunde"){
kundenList.push(result[i]);
}
else if(result[i][0] =="Helfer"){
helferList.push(result[i]);
$('.output').append(result[i][1] + " "+ result[i][2] + ", ");
}
}
$('.output').append("\n");
console.log(kundenList.length);
for(i = 0; i< kundenList.length; i++){
$('.output').append(kundenList[i][1] + " "+ kundenList[i][2] + ", ");
for(j=0; j <helferList.length;j++){
setTimeout(getDistance(kundenList[i],helferList[j]),500);
}
$('.output').append("\n");
}
};
reader.readAsText(file);
}
The problem I have is that I must have a delay between each distance calculation. For this reason I use:
setTimeout(getDistance(kundenList[i],helferList[j]),500);
But it does not seem to work as there is no delay between the calculations