Skip to content

Instantly share code, notes, and snippets.

@inakianduaga
Last active January 23, 2016 22:49
Show Gist options
  • Save inakianduaga/acc56810c936f3439768 to your computer and use it in GitHub Desktop.
Save inakianduaga/acc56810c936f3439768 to your computer and use it in GitHub Desktop.
@inakianduaga
Copy link
Author

Reactivex lesson answers so far

{"answers":["function(console) {\n\tvar names = [\"Ben\", \"Jafar\", \"Matt\", \"Priya\", \"Brian\"],\n\t\tcounter;\n\n\tfor(counter = 0; counter < names.length; counter++) {\n\t\tconsole.log(names[counter]);\n\t}\n}\n\t\t","function(console) {\n\tvar names = [\"Ben\", \"Jafar\", \"Matt\", \"Priya\", \"Brian\"];\n\n\tnames.forEach(name => console.log(name));\n}\n\t\t","function() {\n\tvar newReleases = [\n\t\t{\n\t\t\t\"id\": 70111470,\n\t\t\t\"title\": \"Die Hard\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/DieHard.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": [4.0],\n\t\t\t\"bookmark\": []\n\t\t},\n\t\t{\n\t\t\t\"id\": 654356453,\n\t\t\t\"title\": \"Bad Boys\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/BadBoys.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": [5.0],\n\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t},\n\t\t{\n\t\t\t\"id\": 65432445,\n\t\t\t\"title\": \"The Chamber\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/TheChamber.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": [4.0],\n\t\t\t\"bookmark\": []\n\t\t},\n\t\t{\n\t\t\t\"id\": 675465,\n\t\t\t\"title\": \"Fracture\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/Fracture.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": [5.0],\n\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t}\n\t],\n\tvideoAndTitlePairs = [];\n\n\t// ------------ INSERT CODE HERE! -----------------------------------\n\t// Use forEach function to accumulate {id, title} pairs from each video.\n\t// Put the results into the videoAndTitlePairs array using the Array's\n\t// push() method. Example: videoAndTitlePairs.push(newItem);\n\t// ------------ INSERT CODE HERE! -----------------------------------\n\n  newReleases.forEach(function(release) {\n    videoAndTitlePairs.push({\n      id: release.id,\n      title: release.title\n    });\n  });\n  \n\n\treturn videoAndTitlePairs;\n}\n\t\t","Array.prototype.map = function(projectionFunction) {\n\tvar results = [];\n\tthis.forEach(function(itemInArray) {\n\n\t\t// ------------ INSERT CODE HERE! ----------------------------\n\t\t// Apply the projectionFunction to each item in the array and add\n\t\t// each result to the results array.\n\t\t// Note: you can add items to an array with the push() method.\n\t\t// ------------ INSERT CODE HERE! ----------------------------\n\n    results.push(projectionFunction(itemInArray));\n\t});\n\n\treturn results;\n};\n\n// JSON.stringify([1,2,3].map(function(x) { return x + 1; })) === '[2,3,4]'\n\t\t","function() {\n\tvar newReleases = [\n\t\t{\n\t\t\t\"id\": 70111470,\n\t\t\t\"title\": \"Die Hard\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/DieHard.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": [4.0],\n\t\t\t\"bookmark\": []\n\t\t},\n\t\t{\n\t\t\t\"id\": 654356453,\n\t\t\t\"title\": \"Bad Boys\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/BadBoys.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": [5.0],\n\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t},\n\t\t{\n\t\t\t\"id\": 65432445,\n\t\t\t\"title\": \"The Chamber\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/TheChamber.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": [4.0],\n\t\t\t\"bookmark\": []\n\t\t},\n\t\t{\n\t\t\t\"id\": 675465,\n\t\t\t\"title\": \"Fracture\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/Fracture.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": [5.0],\n\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t}\n\t];\n\n\t// ------------ INSERT CODE HERE! -----------------------------------\n\t// Use map function to accumulate {id, title} pairs from each video.\n  return newReleases.map(function(item){\n    return {\n      id: item.id,\n      title: item.title\n    }\n  })// finish this expression!\n\t// ------------ INSERT CODE HERE! -----------------------------------\n\n}\n\t\t","function() {\n\tvar newReleases = [\n\t\t{\n\t\t\t\"id\": 70111470,\n\t\t\t\"title\": \"Die Hard\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/DieHard.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": 4.0,\n\t\t\t\"bookmark\": []\n\t\t},\n\t\t{\n\t\t\t\"id\": 654356453,\n\t\t\t\"title\": \"Bad Boys\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/BadBoys.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": 5.0,\n\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t},\n\t\t{\n\t\t\t\"id\": 65432445,\n\t\t\t\"title\": \"The Chamber\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/TheChamber.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": 4.0,\n\t\t\t\"bookmark\": []\n\t\t},\n\t\t{\n\t\t\t\"id\": 675465,\n\t\t\t\"title\": \"Fracture\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/Fracture.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": 5.0,\n\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t}\n\t],\n\tvideos = [];\n\n\t// ------------ INSERT CODE HERE! -----------------------------------\n\t// Use forEach function to accumulate every video with a rating of 5.0\n\t// ------------ INSERT CODE HERE! -----------------------------------\n\n  newReleases.forEach(function(release){\n    if(release.rating === 5.0) {\n      videos.push(release);\n    }\n  });\n  \n\treturn videos;\n}\n\t\t","Array.prototype.filter = function(predicateFunction) {\n\tvar results = [];\n\tthis.forEach(function(itemInArray) {\n\t\t// ------------ INSERT CODE HERE! ----------------------------\n\t\t// Apply the predicateFunction to each item in the array.\n\t\t// If the result is truthy, add the item to the results array.\n\t\t// Note: remember you can add items to the array using the array's\n\t\t// push() method.\n\t\t// ------------ INSERT CODE HERE! ----------------------------\n    \n    if(predicateFunction(itemInArray)) {\n      results.push(itemInArray);\n    }\n\t});\n\n\treturn results;\n};\n\n// JSON.stringify([1,2,3].filter(function(x) { return x > 2})) === \"[3]\"\n\t\t","function() {\n\tvar newReleases = [\n\t\t{\n\t\t\t\"id\": 70111470,\n\t\t\t\"title\": \"Die Hard\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/DieHard.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": 4.0,\n\t\t\t\"bookmark\": []\n\t\t},\n\t\t{\n\t\t\t\"id\": 654356453,\n\t\t\t\"title\": \"Bad Boys\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/BadBoys.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": 5.0,\n\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t},\n\t\t{\n\t\t\t\"id\": 65432445,\n\t\t\t\"title\": \"The Chamber\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/TheChamber.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": 4.0,\n\t\t\t\"bookmark\": []\n\t\t},\n\t\t{\n\t\t\t\"id\": 675465,\n\t\t\t\"title\": \"Fracture\",\n\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/Fracture.jpg\",\n\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\"rating\": 5.0,\n\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t}\n\t];\n\n\t// ------------ INSERT CODE HERE! -----------------------------------\n\t// Chain the filter and map functions to select the id of all videos\n\t// with a rating of 5.0.\n\n  return newReleases.filter(function(release) {\n    return release.rating === 5;\n  }).map(function(release) {\n    return release.id;\n  });// Complete this expression\n\t// ------------ INSERT CODE HERE! -----------------------------------\n}\n\t\t","function() {\n\tvar movieLists = [\n\t\t{\n\t\t\tname: \"New Releases\",\n\t\t\tvideos: [\n\t\t\t\t{\n\t\t\t\t\t\"id\": 70111470,\n\t\t\t\t\t\"title\": \"Die Hard\",\n\t\t\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/DieHard.jpg\",\n\t\t\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\"rating\": 4.0,\n\t\t\t\t\t\"bookmark\": []\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": 654356453,\n\t\t\t\t\t\"title\": \"Bad Boys\",\n\t\t\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/BadBoys.jpg\",\n\t\t\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\"rating\": 5.0,\n\t\t\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\tname: \"Dramas\",\n\t\t\tvideos: [\n\t\t\t\t{\n\t\t\t\t\t\"id\": 65432445,\n\t\t\t\t\t\"title\": \"The Chamber\",\n\t\t\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/TheChamber.jpg\",\n\t\t\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\"rating\": 4.0,\n\t\t\t\t\t\"bookmark\": []\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": 675465,\n\t\t\t\t\t\"title\": \"Fracture\",\n\t\t\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/Fracture.jpg\",\n\t\t\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\"rating\": 5.0,\n\t\t\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t],\n\tallVideoIdsInMovieLists = [];\n\n\t// ------------   INSERT CODE HERE!  -----------------------------------\n\t// Use two nested forEach loops to flatten the movieLists into a list of\n\t// video ids.\n\t// ------------   INSERT CODE HERE!  -----------------------------------\n\n  movieLists.forEach(function(movie) {\n    movie.videos.forEach(function(video){\n      allVideoIdsInMovieLists.push(video.id);\n    });\n  });\n  \n\treturn allVideoIdsInMovieLists;\n\n}\n\t\t","Array.prototype.concatAll = function() {\n\tvar results = [];\n\tthis.forEach(function(subArray) {\n\t\t// ------------ INSERT CODE HERE! ----------------------------\n\t\t// Add all the items in each subArray to the results array.\n\t\t// ------------ INSERT CODE HERE! ----------------------------\n    \n    results = results.concat(subArray);\n\t});\n\n\treturn results;\n};\n\n// JSON.stringify([ [1,2,3], [4,5,6], [7,8,9] ].concatAll()) === \"[1,2,3,4,5,6,7,8,9]\"\n// [1,2,3].concatAll(); // throws an error because this is a one-dimensional array\n\t\t","function() {\n\tvar movieLists = [\n\t\t\t{\n\t\t\t\tname: \"New Releases\",\n\t\t\t\tvideos: [\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": 70111470,\n\t\t\t\t\t\t\"title\": \"Die Hard\",\n\t\t\t\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/DieHard.jpg\",\n\t\t\t\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\t\"rating\": 4.0,\n\t\t\t\t\t\t\"bookmark\": []\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": 654356453,\n\t\t\t\t\t\t\"title\": \"Bad Boys\",\n\t\t\t\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/BadBoys.jpg\",\n\t\t\t\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\t\"rating\": 5.0,\n\t\t\t\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"Dramas\",\n\t\t\t\tvideos: [\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": 65432445,\n\t\t\t\t\t\t\"title\": \"The Chamber\",\n\t\t\t\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/TheChamber.jpg\",\n\t\t\t\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\t\"rating\": 4.0,\n\t\t\t\t\t\t\"bookmark\": []\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": 675465,\n\t\t\t\t\t\t\"title\": \"Fracture\",\n\t\t\t\t\t\t\"boxart\": \"http://cdn-0.nflximg.com/images/2891/Fracture.jpg\",\n\t\t\t\t\t\t\"uri\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\t\"rating\": 5.0,\n\t\t\t\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t];\n\n\t// ------------   INSERT CODE HERE!  -----------------------------------\n\t// Use map and concatAll to flatten the movieLists in a list of video ids.\n\t// ------------   INSERT CODE HERE!  -----------------------------------\n\n  \n  movieLists.map(movie => {console.log(movie.videos); return movie.videos;});\n\treturn movieLists.map(movie => movie.videos).concatAll().map(video => video.id);\n\n}\n\t\t","function() {\n\tvar movieLists = [\n\t\t\t{\n\t\t\t\tname: \"Instant Queue\",\n\t\t\t\tvideos : [\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": 70111470,\n\t\t\t\t\t\t\"title\": \"Die Hard\",\n\t\t\t\t\t\t\"boxarts\": [\n\t\t\t\t\t\t\t{ width: 150, height:200, url:\"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg\" },\n\t\t\t\t\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/DieHard200.jpg\" }\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"url\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\t\"rating\": 4.0,\n\t\t\t\t\t\t\"bookmark\": []\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": 654356453,\n\t\t\t\t\t\t\"title\": \"Bad Boys\",\n\t\t\t\t\t\t\"boxarts\": [\n\t\t\t\t\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/BadBoys200.jpg\" },\n\t\t\t\t\t\t\t{ width: 150, height:200, url:\"http://cdn-0.nflximg.com/images/2891/BadBoys150.jpg\" }\n\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"url\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\t\"rating\": 5.0,\n\t\t\t\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"New Releases\",\n\t\t\t\tvideos: [\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": 65432445,\n\t\t\t\t\t\t\"title\": \"The Chamber\",\n\t\t\t\t\t\t\"boxarts\": [\n\t\t\t\t\t\t\t{ width: 150, height:200, url:\"http://cdn-0.nflximg.com/images/2891/TheChamber150.jpg\" },\n\t\t\t\t\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/TheChamber200.jpg\" }\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"url\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\t\"rating\": 4.0,\n\t\t\t\t\t\t\"bookmark\": []\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": 675465,\n\t\t\t\t\t\t\"title\": \"Fracture\",\n\t\t\t\t\t\t\"boxarts\": [\n\t\t\t\t\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture200.jpg\" },\n\t\t\t\t\t\t\t{ width: 150, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture150.jpg\" },\n\t\t\t\t\t\t\t{ width: 300, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture300.jpg\" }\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"url\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\t\"rating\": 5.0,\n\t\t\t\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t];\n\n\n\t// Use one or more map, concatAll, and filter calls to create an array with the following items\n\t// [\n\t//     {\"id\": 675465,\"title\": \"Fracture\",\"boxart\":\"http://cdn-0.nflximg.com/images/2891/Fracture150.jpg\" },\n\t//     {\"id\": 65432445,\"title\": \"The Chamber\",\"boxart\":\"http://cdn-0.nflximg.com/images/2891/TheChamber150.jpg\" },\n\t//     {\"id\": 654356453,\"title\": \"Bad Boys\",\"boxart\":\"http://cdn-0.nflximg.com/images/2891/BadBoys150.jpg\" },\n\t//     {\"id\": 70111470,\"title\": \"Die Hard\",\"boxart\":\"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg\" }\n\t// ];\n\n\treturn movieLists\n\t\t.map(movie => movie.videos)\n\t\t.concatAll()\n\t\t.map(video => video\n\t\t\t.boxarts\n\t\t\t.filter(boxart => boxart.width === 150 && boxart.height === 200)\n\t\t\t.map(boxart => ({\n\t\t\t\t id: video.id,\n\t\t\t\t title: video.title,\n\t\t\t\t boxart: boxart.url\n\t\t\t})))\n\t\t.concatAll();\n\n}\n\t\t","Array.prototype.concatMap = function(projectionFunctionThatReturnsArray) {\n\treturn this.\n\t\tmap(function(item) {\n\t\t\t// ------------   INSERT CODE HERE!  ----------------------------\n\t\t\t// Apply the projection function to each item. The projection\n\t\t\t// function will return an new child array. This will create a\n\t\t\t// two-dimensional array.\n\t\t\t// ------------   INSERT CODE HERE!  ----------------------------\n      \n      return projectionFunctionThatReturnsArray(item);\n\t\t}).\n\t\t// apply the concatAll function to flatten the two-dimensional array\n    \n\t\tconcatAll();\n};\n\n/*\n\tvar spanishFrenchEnglishWords = [ [\"cero\",\"rien\",\"zero\"], [\"uno\",\"un\",\"one\"], [\"dos\",\"deux\",\"two\"] ];\n\t// collect all the words for each number, in every language, in a single, flat list\n\tvar allWords = [0,1,2].\n\t\tconcatMap(function(index) {\n\t\t\treturn spanishFrenchEnglishWords[index];\n\t\t});\n\n\treturn JSON.stringify(allWords) === '[\"cero\",\"rien\",\"zero\",\"uno\",\"un\",\"one\",\"dos\",\"deux\",\"two\"]';\n*/\n\t\t","function() {\n\tvar movieLists = [\n\t\t\t{\n\t\t\t\tname: \"Instant Queue\",\n\t\t\t\tvideos : [\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": 70111470,\n\t\t\t\t\t\t\"title\": \"Die Hard\",\n\t\t\t\t\t\t\"boxarts\": [\n\t\t\t\t\t\t\t{ width: 150, height:200, url:\"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg\" },\n\t\t\t\t\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/DieHard200.jpg\" }\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"url\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\t\"rating\": 4.0,\n\t\t\t\t\t\t\"bookmark\": []\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": 654356453,\n\t\t\t\t\t\t\"title\": \"Bad Boys\",\n\t\t\t\t\t\t\"boxarts\": [\n\t\t\t\t\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/BadBoys200.jpg\" },\n\t\t\t\t\t\t\t{ width: 150, height:200, url:\"http://cdn-0.nflximg.com/images/2891/BadBoys150.jpg\" }\n\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"url\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\t\"rating\": 5.0,\n\t\t\t\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"New Releases\",\n\t\t\t\tvideos: [\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": 65432445,\n\t\t\t\t\t\t\"title\": \"The Chamber\",\n\t\t\t\t\t\t\"boxarts\": [\n\t\t\t\t\t\t\t{ width: 150, height:200, url:\"http://cdn-0.nflximg.com/images/2891/TheChamber150.jpg\" },\n\t\t\t\t\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/TheChamber200.jpg\" }\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"url\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\t\"rating\": 4.0,\n\t\t\t\t\t\t\"bookmark\": []\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"id\": 675465,\n\t\t\t\t\t\t\"title\": \"Fracture\",\n\t\t\t\t\t\t\"boxarts\": [\n\t\t\t\t\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture200.jpg\" },\n\t\t\t\t\t\t\t{ width: 150, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture150.jpg\" },\n\t\t\t\t\t\t\t{ width: 300, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture300.jpg\" }\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"url\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\t\"rating\": 5.0,\n\t\t\t\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t];\n\n\n\t// Use one or more concatMap, map, and filter calls to create an array with the following items\n\t// [\n\t//     {\"id\": 675465,\"title\": \"Fracture\",\"boxart\":\"http://cdn-0.nflximg.com/images/2891/Fracture150.jpg\" },\n\t//     {\"id\": 65432445,\"title\": \"The Chamber\",\"boxart\":\"http://cdn-0.nflximg.com/images/2891/TheChamber150.jpg\" },\n\t//     {\"id\": 654356453,\"title\": \"Bad Boys\",\"boxart\":\"http://cdn-0.nflximg.com/images/2891/BadBoys150.jpg\" },\n\t//     {\"id\": 70111470,\"title\": \"Die Hard\",\"boxart\":\"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg\" }\n\t// ];\n\n\treturn movieLists\n    .concatMap(movie => movie.videos)\n    .concatMap(video => video.boxarts\n      .filter(boxart => boxart.width === 150)\n      .map(boxart => ({\n         id: video.id,\n         title: video.title,\n         boxart: boxart.url\n      }))\n    )    \n    \n\n}\n\t\t","function() {\n\tvar boxarts = [\n\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture200.jpg\" },\n\t\t\t{ width: 150, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture150.jpg\" },\n\t\t\t{ width: 300, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture300.jpg\" },\n\t\t\t{ width: 425, height:150, url:\"http://cdn-0.nflximg.com/images/2891/Fracture425.jpg\" }\n\t\t],\n\t\tcurrentSize,\n\t\tmaxSize = -1,\n\t\tlargestBoxart;\n\n\tboxarts.forEach(function(boxart) {\n\t\tcurrentSize = boxart.width * boxart.height;\n\t\tif (currentSize > maxSize) {\n\t\t\tlargestBoxart = boxart;\n\t\t\tmaxSize = currentSize;\n\t\t}\n\t});\n\n\treturn largestBoxart;\n}\n\t\t","// [1,2,3].reduce(function(accumulatedValue, currentValue) { return accumulatedValue + currentValue; }); === [6];\n// [1,2,3].reduce(function(accumulatedValue, currentValue) { return accumulatedValue + currentValue; }, 10); === [16];\n\nArray.prototype.reduce = function(combiner, initialValue) {\n\tvar counter,\n\t\taccumulatedValue;\n\n\t// If the array is empty, do nothing\n\tif (this.length === 0) {\n\t\treturn this;\n\t}\n\telse {\n\t\t// If the user didn't pass an initial value, use the first item.\n\t\tif (arguments.length === 1) {\n\t\t\tcounter = 1;\n\t\t\taccumulatedValue = this[0];\n\t\t}\n\t\telse if (arguments.length >= 2) {\n\t\t\tcounter = 0;\n\t\t\taccumulatedValue = initialValue;\n\t\t}\n\t\telse {\n\t\t\tthrow \"Invalid arguments.\";\n\t\t}\n\n\t\t// Loop through the array, feeding the current value and the result of\n\t\t// the previous computation back into the combiner function until\n\t\t// we've exhausted the entire array and are left with only one value.\n\t\twhile(counter < this.length) {\n\t\t\taccumulatedValue = combiner(accumulatedValue, this[counter])\n\t\t\tcounter++;\n\t\t}\n\n\t\treturn [accumulatedValue];\n\t}\n};\n\t\t","function() {\n\tvar ratings = [2,3,1,4,5];\n\n\t// You should return an array containing only the largest rating. Remember that reduce always\n\t// returns an array with one item.\n\treturn ratings.\n\t\treduce((reduction, current) => Math.max(current, reduction));\n}\n\t\t","function() {\n\tvar boxarts = [\n\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture200.jpg\" },\n\t\t\t{ width: 150, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture150.jpg\" },\n\t\t\t{ width: 300, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture300.jpg\" },\n\t\t\t{ width: 425, height:150, url:\"http://cdn-0.nflximg.com/images/2891/Fracture425.jpg\" }\n\t\t];\n\n\t// You should return an array containing only the URL of the largest box art. Remember that reduce always\n\t// returns an array with one item.\n\treturn boxarts.\n    reduce((reduction, boxart) => boxart.width > reduction.width ? boxart: reduction)   // Complete this expression\n    .map(boxart => boxart.url);\n}\n\t\t","function() {\n\tvar videos = [\n\t\t{\n\t\t\t\"id\": 65432445,\n\t\t\t\"title\": \"The Chamber\"\n\t\t},\n\t\t{\n\t\t\t\"id\": 675465,\n\t\t\t\"title\": \"Fracture\"\n\t\t},\n\t\t{\n\t\t\t\"id\": 70111470,\n\t\t\t\"title\": \"Die Hard\"\n\t\t},\n\t\t{\n\t\t\t\"id\": 654356453,\n\t\t\t\"title\": \"Bad Boys\"\n\t\t}\n\t];\n\n\t// Expecting this output...\n\t// [\n\t//\t {\n\t//\t\t \"65432445\": \"The Chamber\",\n\t//\t\t \"675465\": \"Fracture\",\n\t//\t\t \"70111470\": \"Die Hard\",\n\t//\t\t \"654356453\": \"Bad Boys\"\n\t//\t }\n\t// ]\n\treturn videos.\n\t\treduce(function(accumulatedMap, video) {\n\n\t\t\t// Object.create() makes a fast copy of the accumulatedMap by\n\t\t\t// creating a new object and setting the accumulatedMap to be the\n\t\t\t// new object's prototype.\n\t\t\t// Initially the new object is empty and has no members of its own,\n\t\t\t// except a pointer to the object on which it was based. If an\n\t\t\t// attempt to find a member on the new object fails, the new object\n\t\t\t// silently attempts to find the member on its prototype. This\n\t\t\t// process continues recursively, with each object checking its\n\t\t\t// prototype until the member is found or we reach the first object\n\t\t\t// we created.\n\t\t\t// If we set a member value on the new object, it is stored\n\t\t\t// directly on that object, leaving the prototype unchanged.\n\t\t\t// Object.create() is perfect for functional programming because it\n\t\t\t// makes creating a new object with a different member value almost\n\t\t\t// as cheap as changing the member on the original object!\n\n\t\t\tvar copyOfAccumulatedMap = Object.create(accumulatedMap);\n\n\t\t\t// ----- INSERT CODE TO ADD THE VIDEO TITLE TO THE ----\n\t\t\t// ----- NEW MAP USING THE VIDEO ID AS THE KEY\t ----\n      copyOfAccumulatedMap[video.id] = video.title;\n      \n\t\t\treturn copyOfAccumulatedMap;\n\t\t},\n\t\t// Use an empty map as the initial value instead of the first item in\n\t\t// the list.\n\t\t{});\n}\n\t\t","function() {\n\tvar movieLists = [\n\t\t{\n\t\t\tname: \"New Releases\",\n\t\t\tvideos: [\n\t\t\t\t{\n\t\t\t\t\t\"id\": 70111470,\n\t\t\t\t\t\"title\": \"Die Hard\",\n\t\t\t\t\t\"boxarts\": [\n\t\t\t\t\t\t{ width: 150, height:200, url:\"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg\" },\n\t\t\t\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/DieHard200.jpg\" }\n\t\t\t\t\t],\n\t\t\t\t\t\"url\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\"rating\": 4.0,\n\t\t\t\t\t\"bookmark\": []\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": 654356453,\n\t\t\t\t\t\"title\": \"Bad Boys\",\n\t\t\t\t\t\"boxarts\": [\n\t\t\t\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/BadBoys200.jpg\" },\n\t\t\t\t\t\t{ width: 140, height:200, url:\"http://cdn-0.nflximg.com/images/2891/BadBoys140.jpg\" }\n\n\t\t\t\t\t],\n\t\t\t\t\t\"url\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\"rating\": 5.0,\n\t\t\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\tname: \"Thrillers\",\n\t\t\tvideos: [\n\t\t\t\t{\n\t\t\t\t\t\"id\": 65432445,\n\t\t\t\t\t\"title\": \"The Chamber\",\n\t\t\t\t\t\"boxarts\": [\n\t\t\t\t\t\t{ width: 130, height:200, url:\"http://cdn-0.nflximg.com/images/2891/TheChamber130.jpg\" },\n\t\t\t\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/TheChamber200.jpg\" }\n\t\t\t\t\t],\n\t\t\t\t\t\"url\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\"rating\": 4.0,\n\t\t\t\t\t\"bookmark\": []\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": 675465,\n\t\t\t\t\t\"title\": \"Fracture\",\n\t\t\t\t\t\"boxarts\": [\n\t\t\t\t\t\t{ width: 200, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture200.jpg\" },\n\t\t\t\t\t\t{ width: 120, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture120.jpg\" },\n\t\t\t\t\t\t{ width: 300, height:200, url:\"http://cdn-0.nflximg.com/images/2891/Fracture300.jpg\" }\n\t\t\t\t\t],\n\t\t\t\t\t\"url\": \"http://api.netflix.com/catalog/titles/movies/70111470\",\n\t\t\t\t\t\"rating\": 5.0,\n\t\t\t\t\t\"bookmark\": [{ id:432534, time:65876586 }]\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t];\n\n\n\t// Use one or more concatMap, map, and reduce calls to create an array with the following items (order doesn't matter)\n\t// [\n\t//\t {\"id\": 675465,\"title\": \"Fracture\",\"boxart\":\"http://cdn-0.nflximg.com/images/2891/Fracture120.jpg\" },\n\t//\t {\"id\": 65432445,\"title\": \"The Chamber\",\"boxart\":\"http://cdn-0.nflximg.com/images/2891/TheChamber130.jpg\" },\n\t//\t {\"id\": 654356453,\"title\": \"Bad Boys\",\"boxart\":\"http://cdn-0.nflximg.com/images/2891/BadBoys140.jpg\" },\n\t//\t {\"id\": 70111470,\"title\": \"Die Hard\",\"boxart\":\"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg\" }\n\t// ];\n\n  return movieLists.\n    concatMap(movie => movie.videos)\n    .concatMap(video => video.boxarts.reduce((smallest, current) => !smallest || smallest.width > current.width ? current : smallest)\n      .map(boxart => ({\n        id: video.id,\n        title: video.title,\n        boxart: boxart.url\n      })));\n}\n\t\t"]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment