Created
February 20, 2018 04:00
-
-
Save ryanvade/7177c8796420fa2b8bc6436426c5ceae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// given an array of teams | |
let teams = teamprovider.getTeams(); // don't remember the exact function name | |
// Create a Map | |
const map = new Map(); | |
teams.forEach((team) => { | |
// get the 'key' | |
const key = team.name; | |
// get a collection by the 'key' | |
const collection = map.get(key); | |
// if the collection doesn't exist, create it | |
if(!collection) { | |
map.set(key, [team]); | |
}else { | |
// if the collection exists, add to the collection | |
collection.push(team); | |
} | |
}); | |
// turn the map into an array of team 'groups' where the groups share the same team name | |
let teamGroupArr = Array.from(map); | |
// do stuff with the group array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment