I have an array with object:
next: [
{
max_score: 5,
outcome: "rest_and_come_back_later"
},
{
max_score: 49,
outcome: "see_a_doctor"
},
{
outcome: "go_to_emergency_room"
}
]
And a variable that holds a patientScore, let us say that the patientScore is 70. If the score is smaller then 5 it should return the outcome rest_and_come_back_later and if it is then max_score 49 it should return the right outcome. If it higher then 49 it should return the outcome : go_to_emergency_room.
What is the best way to do this in javascript?
Does simple ifelse do the job?, like this:
next.forEach((item) => {
if(patientScore < item.max_score && patientScore >= item.max_score){
return console.log("max_score: " + item.max_score)
}else if(patientScore > item.max_score){ return console.log("max_score: " + item.max_score)}})
if(patientScore < item.max_score && patientScore >= item.max_score): how do you believe that thepatientScorecan be both less-thanitem.max_scoreand greater-than-or-equal-to that sameitem.max_score? Did you mean to use||(OR) in place of&&(AND)?