Given the data structure below, write a function that finds the person with the closest age to another person specified as a parameter. Thus, your function should receive two parameters: the staff directory object and a person object. Your function should return an object person.
IN JAVASCRIPT PLEASE
Given the data structure below, write a function that finds the person with the closest age to another person specified as a parameter. Thus, your function should receive two parameters: the staff directory object and a person object. Your function should return an object person.
let staff = [
{id: "U1", name: "Jose", age: 33},
{id: "U2", name: "John", age: 28},
{id: "U3", name: "Mary", age: 27},
{id: "U4", name: "Paul", age: 26}
];
You should test your function in the following way:
let person1 = staff[0];
let closestAgeToPerson1 = getClosestAge(staff, person1);
let person2 = staff[3];
let closestAgeToPerson2 = getClosestAge(staff, person2);
NOTE: The received object is obtained from the staff directory. Thus, when implementing your function, you might use the == operator for performing an equality comparison between two objects. Your tutor can assist you with how to assess object equality in JavaScript. You can find an excellent explanation at http://adripofjavascript.com/blog/drips/object-equality-in-javascript.html