Skip to content

Instantly share code, notes, and snippets.

@stoneboyindc
Last active February 25, 2021 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stoneboyindc/71680635d5c4a6622e26fd24f1946b97 to your computer and use it in GitHub Desktop.
Save stoneboyindc/71680635d5c4a6622e26fd24f1946b97 to your computer and use it in GitHub Desktop.
solution.js
function parkByState(parks) {
const result = parks.reduce((acc, park) => {
let key = park.location.state;
if (!acc[key]) {
acc[key] = [];
}
acc[key].push(park)
return acc
}, {});
return result;
}
function squareKmTotal(parks) {
const parkSquareKms = parks.map((park) => park.areaInSquareKm);
let total = parkSquareKms.reduce((acc, area) => acc + area);
return total
}
/*Return an object where each key is the name of a park and
each value is the state that park is in. */
function parkNameAndState(parks) {
const result = parks.reduce((acc,park, ) => {
acc[park.name] = park.location.state;
return acc;
}, {});
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment