Trusted by Students Everywhere
Why Choose Us?
0% AI Guarantee

Human-written only.

24/7 Support

Anytime, anywhere.

Plagiarism Free

100% Original.

Expert Tutors

Masters & PhDs.

100% Confidential

Your privacy matters.

On-Time Delivery

Never miss a deadline.

You will be working with two different sets of data for these functions: parks and users

Computer Science Jan 31, 2022

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

Expert Solution

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;

}

Archived Solution
Unlocked Solution

You have full access to this solution. To save a copy with all formatting and attachments, use the button below.

Already a member? Sign In
Important Note: This solution is from our archive and has been purchased by others. Submitting it as-is may trigger plagiarism detection. Use it for reference only.

For ready-to-submit work, please order a fresh solution below.

Or get 100% fresh solution
Get Custom Quote
Secure Payment