Skip to content

Instantly share code, notes, and snippets.

@mackenco
Created November 17, 2017 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mackenco/f3df5fce91429a0ad02335bbfe7986d2 to your computer and use it in GitHub Desktop.
Save mackenco/f3df5fce91429a0ad02335bbfe7986d2 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/jupecej
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script>
window.teams = [
{
"id": 133,
"name": "Oakland Athletics",
"link": "/api/v1/teams/133",
"venue": {
"id": 10,
"name": "Oakland Coliseum",
"link": "/api/v1/venues/10",
"location": {
"city": "Oakland",
"state": "California",
"stateAbbrev": "CA"
},
"timeZone": {
"id": "America/Los_Angeles",
"offset": -8,
"tz": "PST"
}
},
"teamCode": "oak",
"fileCode": "oak",
"abbreviation": "OAK",
"teamName": "Athletics",
"locationName": "Oakland",
"firstYearOfPlay": "1901",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 200,
"name": "American League West",
"link": "/api/v1/divisions/200"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Oakland",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 134,
"name": "Pittsburgh Pirates",
"link": "/api/v1/teams/134",
"venue": {
"id": 31,
"name": "PNC Park",
"link": "/api/v1/venues/31",
"location": {
"city": "Pittsburgh",
"state": "Pennsylvania",
"stateAbbrev": "PA"
},
"timeZone": {
"id": "America/New_York",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "pit",
"fileCode": "pit",
"abbreviation": "PIT",
"teamName": "Pirates",
"locationName": "Pittsburgh",
"firstYearOfPlay": "1882",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 205,
"name": "National League Central",
"link": "/api/v1/divisions/205"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Pittsburgh",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 135,
"name": "San Diego Padres",
"link": "/api/v1/teams/135",
"venue": {
"id": 2680,
"name": "Petco Park",
"link": "/api/v1/venues/2680",
"location": {
"city": "San Diego",
"state": "California",
"stateAbbrev": "CA"
},
"timeZone": {
"id": "America/Los_Angeles",
"offset": -8,
"tz": "PST"
}
},
"teamCode": "sdn",
"fileCode": "sd",
"abbreviation": "SD",
"teamName": "Padres",
"locationName": "San Diego",
"firstYearOfPlay": "1969",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 203,
"name": "National League West",
"link": "/api/v1/divisions/203"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "San Diego",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 136,
"name": "Seattle Mariners",
"link": "/api/v1/teams/136",
"venue": {
"id": 680,
"name": "Safeco Field",
"link": "/api/v1/venues/680",
"location": {
"city": "Seattle",
"state": "Washington",
"stateAbbrev": "WA"
},
"timeZone": {
"id": "America/Los_Angeles",
"offset": -8,
"tz": "PST"
}
},
"teamCode": "sea",
"fileCode": "sea",
"abbreviation": "SEA",
"teamName": "Mariners",
"locationName": "Seattle",
"firstYearOfPlay": "1977",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 200,
"name": "American League West",
"link": "/api/v1/divisions/200"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Seattle",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 137,
"name": "San Francisco Giants",
"link": "/api/v1/teams/137",
"venue": {
"id": 2395,
"name": "AT&T Park",
"link": "/api/v1/venues/2395",
"location": {
"city": "San Francisco",
"state": "California",
"stateAbbrev": "CA"
},
"timeZone": {
"id": "America/Los_Angeles",
"offset": -8,
"tz": "PST"
}
},
"teamCode": "sfn",
"fileCode": "sf",
"abbreviation": "SF",
"teamName": "Giants",
"locationName": "San Francisco",
"firstYearOfPlay": "1883",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 203,
"name": "National League West",
"link": "/api/v1/divisions/203"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "San Francisco",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 138,
"name": "St. Louis Cardinals",
"link": "/api/v1/teams/138",
"venue": {
"id": 2889,
"name": "Busch Stadium",
"link": "/api/v1/venues/2889",
"location": {
"city": "St. Louis",
"state": "Missouri",
"stateAbbrev": "MO"
},
"timeZone": {
"id": "America/Chicago",
"offset": -6,
"tz": "CST"
}
},
"teamCode": "sln",
"fileCode": "stl",
"abbreviation": "STL",
"teamName": "Cardinals",
"locationName": "St. Louis",
"firstYearOfPlay": "1892",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 205,
"name": "National League Central",
"link": "/api/v1/divisions/205"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "St. Louis",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 139,
"name": "Tampa Bay Rays",
"link": "/api/v1/teams/139",
"venue": {
"id": 12,
"name": "Tropicana Field",
"link": "/api/v1/venues/12",
"location": {
"city": "St. Petersburg",
"state": "Florida",
"stateAbbrev": "FL"
},
"timeZone": {
"id": "America/New_York",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "tba",
"fileCode": "tb",
"abbreviation": "TB",
"teamName": "Rays",
"locationName": "Tampa Bay",
"firstYearOfPlay": "1998",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 201,
"name": "American League East",
"link": "/api/v1/divisions/201"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Tampa Bay",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 140,
"name": "Texas Rangers",
"link": "/api/v1/teams/140",
"venue": {
"id": 13,
"name": "Globe Life Park in Arlington",
"link": "/api/v1/venues/13",
"location": {
"city": "Arlington",
"state": "Texas",
"stateAbbrev": "TX"
},
"timeZone": {
"id": "America/Chicago",
"offset": -6,
"tz": "CST"
}
},
"teamCode": "tex",
"fileCode": "tex",
"abbreviation": "TEX",
"teamName": "Rangers",
"locationName": "Arlington",
"firstYearOfPlay": "1961",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 200,
"name": "American League West",
"link": "/api/v1/divisions/200"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Texas",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 141,
"name": "Toronto Blue Jays",
"link": "/api/v1/teams/141",
"venue": {
"id": 14,
"name": "Rogers Centre",
"link": "/api/v1/venues/14",
"location": {
"city": "Toronto",
"state": "Ontario",
"stateAbbrev": "ON"
},
"timeZone": {
"id": "America/Toronto",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "tor",
"fileCode": "tor",
"abbreviation": "TOR",
"teamName": "Blue Jays",
"locationName": "Toronto",
"firstYearOfPlay": "1977",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 201,
"name": "American League East",
"link": "/api/v1/divisions/201"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Toronto",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 142,
"name": "Minnesota Twins",
"link": "/api/v1/teams/142",
"venue": {
"id": 3312,
"name": "Target Field",
"link": "/api/v1/venues/3312",
"location": {
"city": "Minneapolis",
"state": "Minnesota",
"stateAbbrev": "MN"
},
"timeZone": {
"id": "America/Chicago",
"offset": -6,
"tz": "CST"
}
},
"teamCode": "min",
"fileCode": "min",
"abbreviation": "MIN",
"teamName": "Twins",
"locationName": "Minneapolis",
"firstYearOfPlay": "1901",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 202,
"name": "American League Central",
"link": "/api/v1/divisions/202"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Minnesota",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 143,
"name": "Philadelphia Phillies",
"link": "/api/v1/teams/143",
"venue": {
"id": 2681,
"name": "Citizens Bank Park",
"link": "/api/v1/venues/2681",
"location": {
"city": "Philadelphia",
"state": "Pennsylvania",
"stateAbbrev": "PA"
},
"timeZone": {
"id": "America/New_York",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "phi",
"fileCode": "phi",
"abbreviation": "PHI",
"teamName": "Phillies",
"locationName": "Philadelphia",
"firstYearOfPlay": "1883",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 204,
"name": "National League East",
"link": "/api/v1/divisions/204"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Philadelphia",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 144,
"name": "Atlanta Braves",
"link": "/api/v1/teams/144",
"venue": {
"id": 4705,
"name": "SunTrust Park",
"link": "/api/v1/venues/4705",
"location": {
"city": "Atlanta",
"state": "Georgia",
"stateAbbrev": "GA"
},
"timeZone": {
"id": "America/New_York",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "atl",
"fileCode": "atl",
"abbreviation": "ATL",
"teamName": "Braves",
"locationName": "Atlanta",
"firstYearOfPlay": "1871",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 204,
"name": "National League East",
"link": "/api/v1/divisions/204"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Atlanta",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 145,
"name": "Chicago White Sox",
"link": "/api/v1/teams/145",
"venue": {
"id": 4,
"name": "Guaranteed Rate Field",
"link": "/api/v1/venues/4",
"location": {
"city": "Chicago",
"state": "Illinois",
"stateAbbrev": "IL"
},
"timeZone": {
"id": "America/Chicago",
"offset": -6,
"tz": "CST"
}
},
"teamCode": "cha",
"fileCode": "cws",
"abbreviation": "CWS",
"teamName": "White Sox",
"locationName": "Chicago",
"firstYearOfPlay": "1901",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 202,
"name": "American League Central",
"link": "/api/v1/divisions/202"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Chi White Sox",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 146,
"name": "Miami Marlins",
"link": "/api/v1/teams/146",
"venue": {
"id": 4169,
"name": "Marlins Park",
"link": "/api/v1/venues/4169",
"location": {
"city": "Miami",
"state": "Florida",
"stateAbbrev": "FL"
},
"timeZone": {
"id": "America/New_York",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "mia",
"fileCode": "mia",
"abbreviation": "MIA",
"teamName": "Marlins",
"locationName": "Miami",
"firstYearOfPlay": "1992",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 204,
"name": "National League East",
"link": "/api/v1/divisions/204"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Miami",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 147,
"name": "New York Yankees",
"link": "/api/v1/teams/147",
"venue": {
"id": 3313,
"name": "Yankee Stadium",
"link": "/api/v1/venues/3313",
"location": {
"city": "Bronx",
"state": "New York",
"stateAbbrev": "NY"
},
"timeZone": {
"id": "America/New_York",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "nya",
"fileCode": "nyy",
"abbreviation": "NYY",
"teamName": "Yankees",
"locationName": "Bronx",
"firstYearOfPlay": "1903",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 201,
"name": "American League East",
"link": "/api/v1/divisions/201"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "NY Yankees",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 158,
"name": "Milwaukee Brewers",
"link": "/api/v1/teams/158",
"venue": {
"id": 32,
"name": "Miller Park",
"link": "/api/v1/venues/32",
"location": {
"city": "Milwaukee",
"state": "Wisconsin",
"stateAbbrev": "WI"
},
"timeZone": {
"id": "America/Chicago",
"offset": -6,
"tz": "CST"
}
},
"teamCode": "mil",
"fileCode": "mil",
"abbreviation": "MIL",
"teamName": "Brewers",
"locationName": "Milwaukee",
"firstYearOfPlay": "1969",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 205,
"name": "National League Central",
"link": "/api/v1/divisions/205"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Milwaukee",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 108,
"name": "Los Angeles Angels",
"link": "/api/v1/teams/108",
"venue": {
"id": 1,
"name": "Angel Stadium of Anaheim",
"link": "/api/v1/venues/1",
"location": {
"city": "Anaheim",
"state": "California",
"stateAbbrev": "CA"
},
"timeZone": {
"id": "America/Los_Angeles",
"offset": -8,
"tz": "PST"
}
},
"teamCode": "ana",
"fileCode": "ana",
"abbreviation": "LAA",
"teamName": "Angels",
"locationName": "Anaheim",
"firstYearOfPlay": "1961",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 200,
"name": "American League West",
"link": "/api/v1/divisions/200"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "LA Angels",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 109,
"name": "Arizona Diamondbacks",
"link": "/api/v1/teams/109",
"venue": {
"id": 15,
"name": "Chase Field",
"link": "/api/v1/venues/15",
"location": {
"city": "Phoenix",
"state": "Arizona",
"stateAbbrev": "AZ"
},
"timeZone": {
"id": "America/Phoenix",
"offset": -7,
"tz": "MST"
}
},
"teamCode": "ari",
"fileCode": "ari",
"abbreviation": "ARI",
"teamName": "D-backs",
"locationName": "Phoenix",
"firstYearOfPlay": "1998",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 203,
"name": "National League West",
"link": "/api/v1/divisions/203"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Arizona",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 110,
"name": "Baltimore Orioles",
"link": "/api/v1/teams/110",
"venue": {
"id": 2,
"name": "Oriole Park at Camden Yards",
"link": "/api/v1/venues/2",
"location": {
"city": "Baltimore",
"state": "Maryland",
"stateAbbrev": "MD"
},
"timeZone": {
"id": "America/New_York",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "bal",
"fileCode": "bal",
"abbreviation": "BAL",
"teamName": "Orioles",
"locationName": "Baltimore",
"firstYearOfPlay": "1901",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 201,
"name": "American League East",
"link": "/api/v1/divisions/201"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Baltimore",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 111,
"name": "Boston Red Sox",
"link": "/api/v1/teams/111",
"venue": {
"id": 3,
"name": "Fenway Park",
"link": "/api/v1/venues/3",
"location": {
"city": "Boston",
"state": "Massachusetts",
"stateAbbrev": "MA"
},
"timeZone": {
"id": "America/New_York",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "bos",
"fileCode": "bos",
"abbreviation": "BOS",
"teamName": "Red Sox",
"locationName": "Boston",
"firstYearOfPlay": "1901",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 201,
"name": "American League East",
"link": "/api/v1/divisions/201"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Boston",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 112,
"name": "Chicago Cubs",
"link": "/api/v1/teams/112",
"venue": {
"id": 17,
"name": "Wrigley Field",
"link": "/api/v1/venues/17",
"location": {
"city": "Chicago",
"state": "Illinois",
"stateAbbrev": "IL"
},
"timeZone": {
"id": "America/Chicago",
"offset": -6,
"tz": "CST"
}
},
"teamCode": "chn",
"fileCode": "chc",
"abbreviation": "CHC",
"teamName": "Cubs",
"locationName": "Chicago",
"firstYearOfPlay": "1874",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 205,
"name": "National League Central",
"link": "/api/v1/divisions/205"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Chi Cubs",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 113,
"name": "Cincinnati Reds",
"link": "/api/v1/teams/113",
"venue": {
"id": 2602,
"name": "Great American Ball Park",
"link": "/api/v1/venues/2602",
"location": {
"city": "Cincinnati",
"state": "Ohio",
"stateAbbrev": "OH"
},
"timeZone": {
"id": "America/New_York",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "cin",
"fileCode": "cin",
"abbreviation": "CIN",
"teamName": "Reds",
"locationName": "Cincinnati",
"firstYearOfPlay": "1882",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 205,
"name": "National League Central",
"link": "/api/v1/divisions/205"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Cincinnati",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 114,
"name": "Cleveland Indians",
"link": "/api/v1/teams/114",
"venue": {
"id": 5,
"name": "Progressive Field",
"link": "/api/v1/venues/5",
"location": {
"city": "Cleveland",
"state": "Ohio",
"stateAbbrev": "OH"
},
"timeZone": {
"id": "America/New_York",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "cle",
"fileCode": "cle",
"abbreviation": "CLE",
"teamName": "Indians",
"locationName": "Cleveland",
"firstYearOfPlay": "1901",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 202,
"name": "American League Central",
"link": "/api/v1/divisions/202"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Cleveland",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 115,
"name": "Colorado Rockies",
"link": "/api/v1/teams/115",
"venue": {
"id": 19,
"name": "Coors Field",
"link": "/api/v1/venues/19",
"location": {
"city": "Denver",
"state": "Colorado",
"stateAbbrev": "CO"
},
"timeZone": {
"id": "America/Denver",
"offset": -7,
"tz": "MST"
}
},
"teamCode": "col",
"fileCode": "col",
"abbreviation": "COL",
"teamName": "Rockies",
"locationName": "Denver",
"firstYearOfPlay": "1992",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 203,
"name": "National League West",
"link": "/api/v1/divisions/203"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Colorado",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 116,
"name": "Detroit Tigers",
"link": "/api/v1/teams/116",
"venue": {
"id": 2394,
"name": "Comerica Park",
"link": "/api/v1/venues/2394",
"location": {
"city": "Detroit",
"state": "Michigan",
"stateAbbrev": "MI"
},
"timeZone": {
"id": "America/Detroit",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "det",
"fileCode": "det",
"abbreviation": "DET",
"teamName": "Tigers",
"locationName": "Detroit",
"firstYearOfPlay": "1901",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 202,
"name": "American League Central",
"link": "/api/v1/divisions/202"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Detroit",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 117,
"name": "Houston Astros",
"link": "/api/v1/teams/117",
"venue": {
"id": 2392,
"name": "Minute Maid Park",
"link": "/api/v1/venues/2392",
"location": {
"city": "Houston",
"state": "Texas",
"stateAbbrev": "TX"
},
"timeZone": {
"id": "America/Chicago",
"offset": -6,
"tz": "CST"
}
},
"teamCode": "hou",
"fileCode": "hou",
"abbreviation": "HOU",
"teamName": "Astros",
"locationName": "Houston",
"firstYearOfPlay": "1962",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 200,
"name": "American League West",
"link": "/api/v1/divisions/200"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Houston",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 118,
"name": "Kansas City Royals",
"link": "/api/v1/teams/118",
"venue": {
"id": 7,
"name": "Kauffman Stadium",
"link": "/api/v1/venues/7",
"location": {
"city": "Kansas City",
"state": "Missouri",
"stateAbbrev": "MO"
},
"timeZone": {
"id": "America/Chicago",
"offset": -6,
"tz": "CST"
}
},
"teamCode": "kca",
"fileCode": "kc",
"abbreviation": "KC",
"teamName": "Royals",
"locationName": "Kansas City",
"firstYearOfPlay": "1969",
"league": {
"id": 103,
"name": "American League",
"link": "/api/v1/league/103"
},
"division": {
"id": 202,
"name": "American League Central",
"link": "/api/v1/divisions/202"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Kansas City",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 119,
"name": "Los Angeles Dodgers",
"link": "/api/v1/teams/119",
"venue": {
"id": 22,
"name": "Dodger Stadium",
"link": "/api/v1/venues/22",
"location": {
"city": "Los Angeles",
"state": "California",
"stateAbbrev": "CA"
},
"timeZone": {
"id": "America/Los_Angeles",
"offset": -8,
"tz": "PST"
}
},
"teamCode": "lan",
"fileCode": "la",
"abbreviation": "LAD",
"teamName": "Dodgers",
"locationName": "Los Angeles",
"firstYearOfPlay": "1884",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 203,
"name": "National League West",
"link": "/api/v1/divisions/203"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "LA Dodgers",
"springLeague": {
"id": 114,
"name": "Cactus League",
"link": "/api/v1/league/114",
"abbreviation": "CL"
},
"active": true
},
{
"id": 120,
"name": "Washington Nationals",
"link": "/api/v1/teams/120",
"venue": {
"id": 3309,
"name": "Nationals Park",
"link": "/api/v1/venues/3309",
"location": {
"city": "Washington",
"state": "District of Columbia",
"stateAbbrev": "DC"
},
"timeZone": {
"id": "America/New_York",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "was",
"fileCode": "was",
"abbreviation": "WSH",
"teamName": "Nationals",
"locationName": "Washington",
"firstYearOfPlay": "1969",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 204,
"name": "National League East",
"link": "/api/v1/divisions/204"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "Washington",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
},
{
"id": 121,
"name": "New York Mets",
"link": "/api/v1/teams/121",
"venue": {
"id": 3289,
"name": "Citi Field",
"link": "/api/v1/venues/3289",
"location": {
"city": "Flushing",
"state": "New York",
"stateAbbrev": "NY"
},
"timeZone": {
"id": "America/New_York",
"offset": -5,
"tz": "EST"
}
},
"teamCode": "nyn",
"fileCode": "nym",
"abbreviation": "NYM",
"teamName": "Mets",
"locationName": "New York",
"firstYearOfPlay": "1962",
"league": {
"id": 104,
"name": "National League",
"link": "/api/v1/league/104"
},
"division": {
"id": 204,
"name": "National League East",
"link": "/api/v1/divisions/204"
},
"sport": {
"id": 1,
"link": "/api/v1/sports/1",
"name": "Major League Baseball"
},
"shortName": "NY Mets",
"springLeague": {
"id": 115,
"name": "Grapefruit League",
"link": "/api/v1/league/115",
"abbreviation": "GL"
},
"active": true
}
];
</script>
</head>
<body>
<ul id="teams"></ul>
<script id="jsbin-javascript">
const teams = window.teams;
/*
* forEach
* When you want to do something with each existing item
* Keyword: SIDE EFFECTS
* Runs: N times
* Returns: Array it was called on
*/
const ul = document.querySelector('#teams');
/*
teams.forEach((team) => {
const li = document.createElement('li');
li.innerHTML = team.name;
ul.appendChild(li);
});
*/
function createAndAppend(team) {
const li = document.createElement('li');
li.innerHTML = team.name;
ul.appendChild(li);
}
teams.forEach(createAndAppend);
/*
* map
* When you want to change each existing item
* Runs N times
* Returns: modified array
*/
//anti-pattern
const ballparks = [];
teams.forEach((team) => {
ballparks.push(team.venue.name);
});
const ballparksMap = teams.map((team) => team.venue.name);
//console.log(ballparksMap);
/*
* filter
* When you want a subset of an array
* Runs N times
* Returns: modified array
*/
//anti-pattern
const alTeams = [];
teams.forEach((team) => {
if (team.league.id === 103) {
alTeams.push(team);
}
});
//console.log(alTeams);
const alTeamsFilter = teams.filter((team) => team.league.id === 103);
//console.log(alTeamsFilter);
/*
* reduce
* Turn many things into one thing
* Runs: N times
* Returns: specified item
*/
//anti-pattern
let years = 0;
teams.forEach((team) => {
const firstYear = parseInt(team.firstYearOfPlay, 10);
years += (2017 - firstYear);
});
//console.log(years);
const yearsReduce = teams.reduce((sum, team) => {
const firstYear = parseInt(team.firstYearOfPlay, 10);
sum += (2017 - firstYear);
return sum;
}, 0);
//console.log(yearsReduce);
/* ------------------------------------------------------- */
//anti-pattern
const springTraining = {
CL: [],
GL: []
};
teams.forEach((team) => {
if (team.springLeague.abbreviation === 'CL') {
springTraining.CL.push(team.name);
} else {
springTraining.GL.push(team.name);
}
});
//console.log(springTraining);
const springTrainingReduce = teams.reduce((obj, team) => {
const abbr = team.springLeague.abbreviation;
obj[abbr] ? obj[abbr].push(team.name) : obj[abbr] = [team.name];
return obj;
}, {});
//console.log(springTrainingReduce);
/* ------------------------------------------------------- */
// stacking
const abbreviations =
teams.filter((team) => team.league.id === 103)
.map((team) => team.abbreviation)
.reduce((str, team) => {
return str += `${team} `;
}, 'AL teams: ');
//console.log(abbreviations);
/*
* some
* when you want to know if _any_ value matches a condition
* Runs N times
* Returns: Boolean
*/
const anOldTeam = teams.some((team) => parseInt(team.firstYearOfPlay, 10) < 1900);
console.log(anOldTeam);
/* a real world example!
const blacklist = ['body#news_article', 'body#news_index', 'body#news_atp'];
const exclude = blacklist.some((selector) => !!document.querySelector(selector));
if (exclude) {
return;
}
*/
/*
* every
* when you want to know if _every_ value matches a condition
* Runs <= N times
* Returns: Boolean
*/
const allActive = teams.every((team) => team.active);
</script>
<script id="jsbin-source-javascript" type="text/javascript">const teams = window.teams;
/*
* forEach
* When you want to do something with each existing item
* Keyword: SIDE EFFECTS
* Runs: N times
* Returns: Array it was called on
*/
const ul = document.querySelector('#teams');
/*
teams.forEach((team) => {
const li = document.createElement('li');
li.innerHTML = team.name;
ul.appendChild(li);
});
*/
function createAndAppend(team) {
const li = document.createElement('li');
li.innerHTML = team.name;
ul.appendChild(li);
}
teams.forEach(createAndAppend);
/*
* map
* When you want to change each existing item
* Runs N times
* Returns: modified array
*/
//anti-pattern
const ballparks = [];
teams.forEach((team) => {
ballparks.push(team.venue.name);
});
const ballparksMap = teams.map((team) => team.venue.name);
//console.log(ballparksMap);
/*
* filter
* When you want a subset of an array
* Runs N times
* Returns: modified array
*/
//anti-pattern
const alTeams = [];
teams.forEach((team) => {
if (team.league.id === 103) {
alTeams.push(team);
}
});
//console.log(alTeams);
const alTeamsFilter = teams.filter((team) => team.league.id === 103);
//console.log(alTeamsFilter);
/*
* reduce
* Turn many things into one thing
* Runs: N times
* Returns: specified item
*/
//anti-pattern
let years = 0;
teams.forEach((team) => {
const firstYear = parseInt(team.firstYearOfPlay, 10);
years += (2017 - firstYear);
});
//console.log(years);
const yearsReduce = teams.reduce((sum, team) => {
const firstYear = parseInt(team.firstYearOfPlay, 10);
sum += (2017 - firstYear);
return sum;
}, 0);
//console.log(yearsReduce);
/* ------------------------------------------------------- */
//anti-pattern
const springTraining = {
CL: [],
GL: []
};
teams.forEach((team) => {
if (team.springLeague.abbreviation === 'CL') {
springTraining.CL.push(team.name);
} else {
springTraining.GL.push(team.name);
}
});
//console.log(springTraining);
const springTrainingReduce = teams.reduce((obj, team) => {
const abbr = team.springLeague.abbreviation;
obj[abbr] ? obj[abbr].push(team.name) : obj[abbr] = [team.name];
return obj;
}, {});
//console.log(springTrainingReduce);
/* ------------------------------------------------------- */
// stacking
const abbreviations =
teams.filter((team) => team.league.id === 103)
.map((team) => team.abbreviation)
.reduce((str, team) => {
return str += `${team} `;
}, 'AL teams: ');
//console.log(abbreviations);
/*
* some
* when you want to know if _any_ value matches a condition
* Runs N times
* Returns: Boolean
*/
const anOldTeam = teams.some((team) => parseInt(team.firstYearOfPlay, 10) < 1900);
console.log(anOldTeam);
/* a real world example!
const blacklist = ['body#news_article', 'body#news_index', 'body#news_atp'];
const exclude = blacklist.some((selector) => !!document.querySelector(selector));
if (exclude) {
return;
}
*/
/*
* every
* when you want to know if _every_ value matches a condition
* Runs <= N times
* Returns: Boolean
*/
const allActive = teams.every((team) => team.active);
</script></body>
</html>
const teams = window.teams;
/*
* forEach
* When you want to do something with each existing item
* Keyword: SIDE EFFECTS
* Runs: N times
* Returns: Array it was called on
*/
const ul = document.querySelector('#teams');
/*
teams.forEach((team) => {
const li = document.createElement('li');
li.innerHTML = team.name;
ul.appendChild(li);
});
*/
function createAndAppend(team) {
const li = document.createElement('li');
li.innerHTML = team.name;
ul.appendChild(li);
}
teams.forEach(createAndAppend);
/*
* map
* When you want to change each existing item
* Runs N times
* Returns: modified array
*/
//anti-pattern
const ballparks = [];
teams.forEach((team) => {
ballparks.push(team.venue.name);
});
const ballparksMap = teams.map((team) => team.venue.name);
//console.log(ballparksMap);
/*
* filter
* When you want a subset of an array
* Runs N times
* Returns: modified array
*/
//anti-pattern
const alTeams = [];
teams.forEach((team) => {
if (team.league.id === 103) {
alTeams.push(team);
}
});
//console.log(alTeams);
const alTeamsFilter = teams.filter((team) => team.league.id === 103);
//console.log(alTeamsFilter);
/*
* reduce
* Turn many things into one thing
* Runs: N times
* Returns: specified item
*/
//anti-pattern
let years = 0;
teams.forEach((team) => {
const firstYear = parseInt(team.firstYearOfPlay, 10);
years += (2017 - firstYear);
});
//console.log(years);
const yearsReduce = teams.reduce((sum, team) => {
const firstYear = parseInt(team.firstYearOfPlay, 10);
sum += (2017 - firstYear);
return sum;
}, 0);
//console.log(yearsReduce);
/* ------------------------------------------------------- */
//anti-pattern
const springTraining = {
CL: [],
GL: []
};
teams.forEach((team) => {
if (team.springLeague.abbreviation === 'CL') {
springTraining.CL.push(team.name);
} else {
springTraining.GL.push(team.name);
}
});
//console.log(springTraining);
const springTrainingReduce = teams.reduce((obj, team) => {
const abbr = team.springLeague.abbreviation;
obj[abbr] ? obj[abbr].push(team.name) : obj[abbr] = [team.name];
return obj;
}, {});
//console.log(springTrainingReduce);
/* ------------------------------------------------------- */
// stacking
const abbreviations =
teams.filter((team) => team.league.id === 103)
.map((team) => team.abbreviation)
.reduce((str, team) => {
return str += `${team} `;
}, 'AL teams: ');
//console.log(abbreviations);
/*
* some
* when you want to know if _any_ value matches a condition
* Runs N times
* Returns: Boolean
*/
const anOldTeam = teams.some((team) => parseInt(team.firstYearOfPlay, 10) < 1900);
console.log(anOldTeam);
/* a real world example!
const blacklist = ['body#news_article', 'body#news_index', 'body#news_atp'];
const exclude = blacklist.some((selector) => !!document.querySelector(selector));
if (exclude) {
return;
}
*/
/*
* every
* when you want to know if _every_ value matches a condition
* Runs <= N times
* Returns: Boolean
*/
const allActive = teams.every((team) => team.active);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment