Detector with closures

I have an array of symptoms and a min num of symptoms that the person can get for considering if he is sick or not.

this is an example :

var symptoms = ['fever', 'dry cough', 'tiredness', 'sore throat', 'diarrhoea', 'loss of taste', 'loss of smell'];

//   var covidDetector = closureDetect(symptoms, 3);

//   var personOne = {

//     name: 'Franco',

//     age: 26,

//     symptoms: ['fever', 'congestion', 'loss of taste', 'tiredness']

//   }

//   var personTwo = {

//     name: 'Toni',

//     age: 30,

//     symptoms: ['congestion', 'tiredness']

//   }

//

//   covidDetector(personOne); --> true

//   covidDetector(personTwo); --> false

and i have this code so far but doesn’t seems to work and idk why:

function closureDetect(symptoms, min) {

  return function (person) {

    if (person.symptoms.length >= min) {

      return true;

    } else {

      return false;

    }

  };

}

its all using closures

Can you be more specific about why it isn’t working? What errors are you getting?

I’ve tried both examples (after uncommenting out code in the first part) and got the expected results.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.