#Profile Lookup#I think camperbot's code can not handdle some case

#Profile Lookup#I think camperbot's code can not handdle some case
0.0 0

#1

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
}

#2

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#3

With this setup you can’t handle this case. You would need something like a unique ID for each contact.

That is, unless you assume that duplicate firstNames are the same person. But if you assume that the same firstName does not indicate the same person, there is no way to know what to return.