Skip to content

Instantly share code, notes, and snippets.

@peaceintheheart
Created December 18, 2020 19:44
Show Gist options
  • Save peaceintheheart/1059c0c48172082471a87b0966bae06a to your computer and use it in GitHub Desktop.
Save peaceintheheart/1059c0c48172082471a87b0966bae06a to your computer and use it in GitHub Desktop.
A solution
function findMyCampsites (campgrounds, viewToMatch, partySizeToMatch){
let dreamSite =[];
let sorryMessage = "Sorry, no campsites with that view are available to host your party";
for (let i = 0; i< campgrounds.length; i++){
if (campgrounds[i].isReserved === false &&
campgrounds[i].view === viewToMatch &&
campgrounds[i].partySize >= partySizeToMatch){
dreamSite.push(campgrounds[i].number);
}
}
if (dreamSite.length == 0) {
return sorryMessage;
}
return dreamSite;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment