I’ve seen the standard code written by camperbot and I came up with one question with it’s code.
What if two guy have a same FirstName, and one of them have the required property while another one does not?
I think camperbot’s code can not handdle this case.
What’s your oppion?
I’m sorry for my poor English level…
comperbot’s code are given below:
for (var x = 0; x < contacts.length; x++){
if (contacts[x].firstName === firstName) {
if (contacts[x].hasOwnProperty(prop)) {
return contacts[x][prop];
} else {
return "No such property";
}
}
}
return "No such contact";
//my own code are given as below:
function lookUpProfile(firstName, prop){
// Only change code below this line
var find=false;
for(var i=0;i<contacts.length;i++){
if(contacts[i].hasOwnProperty(prop)){
find=true;
}
}
if(!find) return "No such property";
for(var i=0;i<contacts.length;i++){
if(contacts[i]["firstName"]===firstName){
return contacts[i][prop];
}
}
return "No such contact";
// Only change code above this line
}