So, I have basically finished the classes lesson and I have a few practical questions.
Should I use the factory function or classes to create profiles?
Right now I have built a basic example with a few profiles, using the factory function but I can’t see how I can “search” through the objects.
const profileFactory = (name, nationality, hobby, favFood, profession, languagesSpoken) => {
return {
name,
nationality,
hobby,
favFood,
profession,
languagesSpoken
};
};
const anna = profileFactory(‘anna’, ‘britain’, ‘dancing’, ‘rice’, ‘student’, ‘english’);
const david = profileFactory(‘david’, ‘sweden’, [‘football’, ‘painting’], ‘meatballs’, ‘networker’, [‘Swedish’, ‘English’, ‘Spanish’, ‘French’, ‘Italian’, ‘German’, ‘Dutch’]);
const helen = profileFactory(‘helen’, ‘sweden’, [‘knitting’, ‘painting’] , ‘vegetables’, ‘retired’, [‘English’, ‘French’, ‘Dutch’, ‘Spanish’, ‘Greek’, ‘Swedish’, ‘Hungarian’, ‘Italian’]);
For the code above, how could I return only the profiles that have nationality = swedish, hobby = painting, and languagesSpoken = English, Swedish and Italian for example? I want it to return the full profile of both david and helen.
What would the code look like?
Right now I’m imagining that I need to use classes instead so that it knows which objects to search through? but is it possible using just the factory funtion? Should I use a loop?
Thanks again for the help!