I have an array that i have made have two of the same value, i have made a function to check the array for duplicates but for some reason it never goes into the if statement. ( if(array[i] == array[j]) ).
when i is 0 and j is 1 they should be matching.
let sessions = [
{"title": "Lecture", "sessionTime": new Date(2021, 8, 28, 9), "staff": "example"},
{"title": "fake", "sessionTime": new Date(2021, 8, 28, 9), "staff": "example"},
{"title": "Lab 1", "sessionTime": new Date(2021, 8, 28, 14), "staff": "example"},
{"title": "Lab 2", "sessionTime": new Date(2021, 9, 1, 11), "staff": "example"}
];
errorCheck1 = function(sessions) {
for (let i = 0; i < sessions.length; i++) {
for (let j = 0; j < sessions.length; j++) {
if (i != j) {
if (sessions[i].sessionTime == sessions[j].sessionTime) {
$("#errors").append("<li>" + sessions[i].title + " clashes with " + sessions[j].title +"</li>");
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire