I am looking to compare a dictionary that contains specific preferences of a coachee with other dictionaries that hold the profiles of coaches.
Each coach will receive a score based on how well they match the coachee's preferences, or be excluded with a score of -1 if they do not meet an important preference.
One coachee will be compared to 24 coaches in order to determine the best match.
QUESTION: How can I efficiently loop through this process?
Below is a sample code:
//coachee\\
var coachee = {
"gender": 1,
"age_option_1": 1,
"age_option_2": 1,
"age_option_3": 0,
"topics_option_1": 1,
"topics_option_2": 0,
"topics_option_3": 0,
"industry_option_1": 1,
"industry_option_2": 0,
"industry_option_3": 0,
"experience_option_1": 1,
"experience_option_2": 0,
"experience_option_3": 1,
"language_option_1": 1,
"language_option_2": 0,
"language_option_3": 0
}
//coach1\\
var coach1 = {
coach1_answers_gender : 2,
coach1_answers_age_option_1 : 0,
coach1_answers_age_option_2 : 1,
coach1_answers_age_option_3 : 0,
coach1_answers_topics_option_1 : 1,
coach1_answers_topics_option_2 : 0,
coach1_answers_topics_option_3 : 1,
coach1_answers_industry_option1 : 1,
coach1_answers_industry_option2 : 1,
coach1_answers_industry_option3 : 0,
coach1_answers_experience_option1 : 1,
coach1_answers_experience_option2 : 1,
coach1_answers_experience_option3 : 0,
coach1_answers_language_option_1 : 1,
coach1_answers_language_option_2 : 1,
coach1_answers_language_option_3 : 1
};
///COMPARISON///
//Topics//
if (answers["topics_option_1"] == 1 && coach1_answers_topics_option_1 == 1) {
coach1_topics1_score = 1;
} else {
coach1_topics1_score = 0;
}
if (answers["topics_option_2"] == 1 && coach1_answers_topics_option_2 == 1) {
coach1_topics2_score = 1;
} else {
coach1_topics2_score = 0;
}
if (answers["topics_option_3"] == 1 && coach1_answers_topics_option_3 == 1) {
coach1_topics3_score = 1;
} else {
coach1_topics3_score = 0;
}
var coach1_topics_score = coach1_topics1_score + coach1_topics2_score + coach1_topics3_score;
//Industry//
if (answers["industry_option_1"] == 1 && coach1_answers_industry_option1 == 1) {
coach1_industry1_score = 1;
} else {
coach1_industry1_score = 0;
}
if (answers["industry_option_2"] == 1 && coach1_answers_industry_option2 == 1) {
coach1_industry2_score = 1;
} else {
coach1_industry2_score = 0;
}
if (answers["industry_option_3"] == 1 && coach1_answers_industry_option3 == 1) {
coach1_industry3_score = 1;
} else {
coach1_industry3_score = 0;
}
var coach1_industry_score = coach1_industry1_score + coach1_industry2_score + coach1_industry3_score;
//Experience//
if (answers["experience_option_1"] == 1 && coach1_answers_experience_option1 == 1) {
coach1_experience1_score = 1;
} else {
coach1_experience1_score = 0;
}
if (answers["experience_option_2"] == 1 && coach1_answers_experience_option2 == 1) {
coach1_experience2_score = 1;
} else {
coach1_experience2_score = 0;
}
if (answers["experience_option_3"] == 1 && coach1_answers_experience_option3 == 1) {
coach1_experience3_score = 1;
} else {
coach1_experience3_score = 0;
}
var coach1_experience_score = coach1_experience1_score + coach1_experience2_score + coach1_experience3_score;
//Total Score//
var coach1_score = (coach1_age_score + coach1_topics_score + coach1_industry_score + coach1_experience_score) * 10;
///EXCLUSION///
//Age//
if (answers["age_option_1"] == 1 && coach1_answers_age_option_1 == 1) {
coach1_age_score = 1;
} else if (answers["age_option_2"] == 1 && coach1_answers_age_option_2 == 1) {
coach1_age_score = 1;
} else if (answers["age_option_3"] == 1 && coach1_answers_age_option_3 == 1) {
coach1_age_score = 1;
} else {
coach1_score = -1;
}
//Language//
if (answers["language_option_1"] == 1 && coach1_answers_language_option_1 == 1 ) {
coach1_language_score = 1;
} else if (answers["language_option_2"] == 1 && coach1_answers_language_option_2 == 1 ) {
coach1_language_score = 1;
} else if (answers["language_option_3"] == 1 ) {
coach1_language_score = 1;
} else {
coach1_score = -1;
}
//Gender//
if (answers["gender"] == 3) {
coach1_gender_score = 1;
} else if (answers["gender"] == coach1_answers_gender) {
coach1_gender_score = 1;
} else {
coach1_score = -1;
}
//Repeat for Coach2 and other coaches...
The goal is to have an array of scores such as:
coaches_score = [coach1_score, coach2_score, ...]
Manually repeating the comparison and exclusion blocks for each coach would be time-consuming. Is there a way to efficiently loop through this process? Your insights are greatly appreciated.
Thank you!