Skip to content

Instantly share code, notes, and snippets.

@devmeireles
Created January 19, 2019 13:02
Show Gist options
  • Save devmeireles/58314e2165cbbd8c3ff3716ac353bf16 to your computer and use it in GitHub Desktop.
Save devmeireles/58314e2165cbbd8c3ff3716ac353bf16 to your computer and use it in GitHub Desktop.
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