I have an object:
EURO_COUNTRIES = ['France', 'Germany', 'Spain']
fruit_production = {
cuba: {
#meaning: country c produces k kilograms of fruit in region r for season s
winter: [{north: 1}, {south: nil}, {east: 4}, {west: 4}],
summer: [{north: nil}, {south: 5}, {east: ""}, {west: 5}],
},
spain: {
fall: [{north: 7}, {}],
summer: [{north: nil}, {south: "5"}, {east: 2}, {west: '5'}],
spring: []
}
#and the list goes on for hundreds of countries
}fruit_production = {
cuba: {
#meaning: country c produces k kilograms of fruit in region r for season s
winter: [{north: 1}, {south: nil}, {east: 4}, {west: 4}],
summer: [{north: nil}, {south: 5}, {east: ""}, {west: 5}],
},
spain: {
fall: [{north: 7}, {}],
summer: [{north: nil}, {south: "5"}, {east: 2}, {west: '5'}],
spring: []
}
#and the list goes on for hundreds of countries
}
I tried to convert it to JSON object with json.parse(fruit_production), but how can I can actually get the data from it and loop it after that? For example:
- Return the country with the highest year-round fruit yield
- Return the European country with the highest warm season (spring, summer) fruit yield
- Return a mapping from country to total yearly yield, i.e {netherlands: 1818, thailand: 8200, etc...}
- Return a mapping of the total worldwide yields per region, e.g {north: 28333, south: 91339, east: 14343, west: 50290}