Last active
February 25, 2021 22:38
-
-
Save stoneboyindc/71680635d5c4a6622e26fd24f1946b97 to your computer and use it in GitHub Desktop.
solution.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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