JSFiddle - React, Tailwind, and code Playground
by lavisha99
JavaScript
function student(name, interests) {
this.name = name;
this.interests = interests;
}
function directory() {
this.studentArray = []; //trying to create a list of all students
this.addStudent = function(student) {
studentArray.push(student);
}
this.findSimilar = function(student) {
let comparisons = [];
let myInt = student.interests //easy access to the student we are comparing to
for (let j = 0; j < studentArray.length; j++) {
for (let k = 0; k < studentArray[j].interests.length; k++) {
let similarityScore = 0;
if (myInt.includes(this.studentArray[j].interests[k])) {
similarityScore++
}
comparisons.push({
name: this.studentArray[j].name,
similarityScore: similarityScore
})
}
}
}
}