Created
January 19, 2019 13:02
-
-
Save devmeireles/58314e2165cbbd8c3ff3716ac353bf16 to your computer and use it in GitHub Desktop.
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
var each = require('foreach'); | |
var league = [ | |
{ | |
"time": "São Paulo", | |
"liga": "Brasil", | |
"estadio": [ | |
{ | |
"estadio_nome": "Morumbi", | |
"capacidade": 60000 | |
} | |
] | |
}, | |
{ | |
"time": "Santos", | |
"liga": "Brasil", | |
"estadio": [ | |
{ | |
"estadio_nome": "Vila Belmiro", | |
"capacidade": 16068 | |
} | |
] | |
}, | |
{ | |
"time": "Independiente", | |
"liga": "Argentina", | |
"estadio": [ | |
{ | |
"estadio_nome": "Estádio Libertadores de América", | |
"capacidade": 52000 | |
} | |
] | |
}, | |
{ | |
"time": "River Plate", | |
"liga": "Argentina", | |
"estadio": [ | |
{ | |
"estadio_nome": "Monumental de Nuñes", | |
"capacidade": 66269 | |
} | |
] | |
}, | |
] | |
time = [] | |
var ligas = {} | |
each([league], function (value, key, array) { | |
for (var i = 0; i < value.length; i++) { | |
ligas = value.reduce(function (key, item) { | |
key[item.liga] = key[item.liga] || [] | |
key[item.liga].push(item.time) | |
return key | |
}, Object.create(null)) | |
} | |
}); | |
console.log(ligas) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment