I'm trying to refactor this function, but have hit a wall. What the function attempts to accomplish is find whether or not a contact exists within a JSON object, and if it does, determine if the second parameter provided is a property that exists on the specified object.
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];
function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
if (contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop)) {
retu contacts[i][prop];
}
}
for (var j = 0; j < contacts.length; j++) {
if (contacts[j].firstName !== firstName) {
retu "No such contact";
} else if (!contacts[j].hasOwnProperty(!prop)) {
retu "No such property" ;
}
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("kyle", "lastName");
