From 2161c4834ec9098363d36d788f1bf390780a012c Mon Sep 17 00:00:00 2001 From: "Alex Xu (Hello71)" Date: Sat, 22 Sep 2018 09:07:54 -0400 Subject: fix "other options" --- script.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/script.js b/script.js index 9ec7707..0951b5b 100644 --- a/script.js +++ b/script.js @@ -320,23 +320,27 @@ function ready() { // 2. most recent faculty for this subject // 3. most recent compatible faculty // 4. first compatible faculty - if (SUBJS.hasOwnProperty(state["subj"])) { - var compat_facs = SUBJS[state["subj"]]; - let other_facs = compat_facs - .filter(f => f != state["fac"]) - .map(f => `${f}`) - .join(", "); - var other_options = `, other options: ${other_facs}`; + let compat_facs = SUBJS[state["subj"]]; + let other_options = function () { + if (compat_facs) { + let other_facs = compat_facs + .filter(f => f != state["fac"]) + .map(f => `${f}`) + .join(", "); + if (other_facs.length) + return ", other options: " + other_facs; + } + return ""; } // 1. most recent faculty for this course if (state["crsn"] && cached_ycq_s.course_facs[state["subj"] + state["crsn"]]) { state["fac"] = cached_ycq_s.course_facs[state["subj"] + state["crsn"]]; - warn.push(`using saved faculty for ${state["subj"]} ${state["crsn"]}: ${state["fac"]}${other_options}`); + warn.push(`using saved faculty for ${state["subj"]} ${state["crsn"]}: ${state["fac"]}${other_options()}`); } else if (cached_ycq_s.subj_facs[state["subj"]]) { // 2. most recent faculty for this subject state["fac"] = cached_ycq_s.subj_facs[state["subj"]]; - warn.push(`using saved faculty for ${state["subj"]}: ${state["fac"]}${other_options}`); + warn.push(`using saved faculty for ${state["subj"]}: ${state["fac"]}${other_options()}`); } else if (compat_facs) { // 3. most recent compatible faculty if (cached_ycq_s.default_facs) @@ -345,11 +349,11 @@ function ready() { state["fac"] = cached_ycq_s.default_facs[i]; if (state["fac"]) { - warn.push(`using saved faculty: ${state["fac"]}${other_options}`); + warn.push(`using saved faculty: ${state["fac"]}${other_options()}`); } else { // 4. first compatible faculty state["fac"] = compat_facs[0]; - warn.push(`using default faculty for ${state["subj"]}: ${state["fac"]}${other_options}`); + warn.push(`using default faculty for ${state["subj"]}: ${state["fac"]}${other_options()}`); } } else { error.push("no faculty provided and unknown subject"); -- cgit v1.2.3-54-g00ecf