Fill This Form To Receive Instant Help
Homework answers / question archive / You will be working with two different sets of data for these functions: parks and users
You will be working with two different sets of data for these functions: parks and users.
Parks is an array of objects, similar to this:
const parks = [
{
id: 1,
name: "Acadia",
areaInSquareKm: 198.6,
location: { state: "Maine" },
},
{
id: 2,
name: "Canyonlands",
areaInSquareKm: 1366.2,
location: { state: "Utah" },
},
{
id: 3,
name: "Zion",
areaInSquareKm: 595.9,
location: { state: "Utah" },
},
];
Users is an object with a number of keys that represents each user. It looks something like this:
const users = {
"karah.branch3": {
visited: [2],
wishlist: [1, 3],
},
"dwayne.m55": {
visited: [2, 3],
wishlist: [1],
},
};
userHasVisitedAllParksInState
This function returns a boolean that represents whether or not a user has visited all parks in the parks array from a given state.
userHasVisitedAllParksInState(parks, users, "Utah", "dwayne.m55"); //> true
userHasVisitedAllParksInState(parks, users, "Utah", "karah.branch3"); //> false
function userHasVisitedAllParksInState(parks, users, state, username) {
var allParks = parks.filter((park) => park.location.state === state);
var parkIds = new Set();
allParks.forEach((value)=> {parkIds.add(value.id);});
users[username].visited.forEach((value)=> {parkIds.delete(value);});
return parkIds.size === 0;
}