Skip to content

Instantly share code, notes, and snippets.

@devmeireles
Created January 21, 2019 19:15
Show Gist options
  • Save devmeireles/7066d54bfe9e5e427256b733d156236c to your computer and use it in GitHub Desktop.
Save devmeireles/7066d54bfe9e5e427256b733d156236c to your computer and use it in GitHub Desktop.
var each = require('foreach')
var fs = require('fs')
var content = fs.readFileSync('./data/static/teams.json', 'utf-8')
var ligas = {}
var equipos = JSON.parse(content)
each([equipos], 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.equipo)
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