Tell us what’s happening:
Hi! So, I solved this problem but I just wanted to get some feedback on whether on not this is an efficient solution when compared to the ones that are already given as answers.
How can I judge whether or not one solution is better than another? If so, then what are the parameters of deciding so?
All feedback is accepted!
Your code so far
let users = {
Alan: {
age: 27,
online: true
},
Jeff: {
age: 32,
online: true
},
Sarah: {
age: 48,
online: true
},
Ryan: {
age: 19,
online: true
}
};
function isEveryoneHere(obj) {
// Only change code below this line
const check = ['Alan', 'Jeff', 'Sarah', 'Ryan'];
for(let i = 0; i < check.length; i++){
let user = check[i];
if(!users.hasOwnProperty(user)){
return false;
} else {
continue;
}
// Only change code above this line
}
return true;
}
console.log(isEveryoneHere(users));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0.
Challenge: Check if an Object has a Property
Link to the challenge:
