Я должен использовать значение currenttest, чтобы найти текущее местоположение в массиве testorder. Мне нужно начать с этого индекса и продвигаться вперед в поисках истинной доступности. Любая помощь приветствуется. Недостатком в текущем коде является то, что трудно полностью протестировать каждый путь кода в функции "if (mode ==" bpw "& currenttest ==" ECG ")"
var json_data = {
"Blood Pressure": true,
"Weight Scale": true,
"Body Composition": true,
"ECG": true,
"SPO2": false,
"temp": true
};
var hardwarelist = [];
var testorder = ["Blood Pressure", "Weight Scale", "Body Composition", "ECG", "SPo2", "temp"];
for (var i in json_data) {
hardwarelist.push([i, json_data[i]]);
}
var trueVitals = hardwarelist.filter(([, e]) => e).map(([e]) => e);
var mode = "bpw";
var currenttest = "ECG";
nextTest(mode, currenttest);
function nextTest(mode, currenttest) {
var currenttestorder = (testorder.indexOf(currenttest));
if (mode == "bpw" & currenttest == "ECG") {
if(trueVitals.includes("Weight Scale"){
window.location.href = "#/about";
}
else if (trueVitals.includes("ECG")) {
window.location.href = "#/services";
} else if (trueVitals.includes("SPO2")) {
window.location.href = "#/contact";
} else if (trueVitals.includes("Body Composition")) {
window.location.href = "#/blog";
} else if (trueVitals.includes("temp")) {
window.location.href = "#/faq";
}
}
}