Skip to content

Instantly share code, notes, and snippets.

@hannahhch
Last active April 8, 2022 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save hannahhch/f98e3faa0dcccb26259e93bdc75661ec to your computer and use it in GitHub Desktop.
Save hannahhch/f98e3faa0dcccb26259e93bdc75661ec to your computer and use it in GitHub Desktop.

Trails

const fountainValleyLoopTrail = {
  name: 'Fountain Valley Loop',
  location: 'Littleton, CO',
  distance: 2.3,
  traffic: 'moderate',
  features: ['bird watching','hiking','cross country skiing','snowshoeing']
}

const emeraldLakeTrail = {
  name: 'Emerald Lake',
  location: 'Estes Park, CO',
  distance: 3.1,
  traffic: 'heavy',
  features: ['bird watching', 'hiking', 'fishing']
}

Level One

Write a function called displayTrailData that will take in any single object of trail data from above. It should return an array of strings. Passing in fountainValleyLoopTrail should return:

[ 
  'The trail name: Fountain Valley Loop',
  'The trail location: Littleton, CO',
  'The trail distance:  2.3',
  'The trail traffic: moderate',
  'The trail features: bird watching, hiking, cross country skiing, snowshoeing'
 ];

Level Two

const favoriteActivities = [
 { name: 'hiking', preferenceLevel: 9  },
 { name: 'fishing', preferenceLevel: 7 },
 { name: 'snowshoeing', preferenceLevel: 0 },
 { name: 'bird watching', preferenceLevel: 6 },
]

Refactor your function so that you can pass in a second parameter of favoriteActivities. Sort the trail features by preferenceLevel so that my favorite activites show first. Now when you pass in fountainValleyLoopTrail and favoriteActivities, you should return the following, because hiking has the highest preference level.

[ 
'The trail name: Fountain Valley Loop',
 'The trail location: Littleton, CO',
 'The trail distance:  2.3',
 'The trail traffic: moderate',
 'The trail features: hiking, bird watching, snowshoeing'
];

NOTE: What happens if my preference activities and the trail feautures don't match up 100%?

Level Three

Refactor your function to remove activities that have a 0 preferenceLevel. Now when you pass in fountainValleyLoopTrail and favoriteActivities, you should return the following, because snowshoeing has a preferenceLevel of 0.

[ 
 'The trail name: Fountain Valley Loop',
'The trail location: Littleton, CO',
'The trail distance:  2.3',
'The trail traffic: moderate',
'The trail features: hiking, bird watching'
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment