Concatall:
Array.prototype.concatAll = function () { var results = []; This . ForEach (function (subarray) { // ------------INSERT CODE here!-------------------------- - -// ADD all the items in each subarray to the results array . // ------------INSERT CODE here!---------------------------- Subarray.foreach (function (sub) { Results.push (sub) }) }); return results;};
Exercise 12:retrieve ID, title, and a 150x200 box art URL for every video
You've managed to flatten a tree that ' s the levels deep and let's try for three! Let's say that instead of a single boxart URLs on each video, we had a collection of Boxart objects, each with a different Size and URL. Create a query that selects {ID, title, boxart} for every video in the movielists. This time though, the Boxart property in the result would be is the URL of the Boxart object with dimensions of 150x200px. Let's see if you can solve this problem with map (), Concatall (), and filter ().
There ' s just more one thing:you can ' t use indexers. In other words, this is illegal:
var iteminarray = movielists[0];
Furthermore, you ' re not allowed to use indexers in any of the remaining exercises unless you ' re implementing one of the FI ve functions. There is a very good reason for this restriction, and that reason would eventually be explained. For now, you ' ll simply has to accept it on faith, the this restriction serves a purpose. :-)
function() { varMovielists =[{name:"Instant Queue", Videos: [{"id": 70111470, "title": "Die Hard", "Boxarts": [{width:height:200, url: "Http://cdn-0.nflximg.com/images/2891/DieHard150.jpg"}, {width:$, height:200, url: "Http://cdn-0.nflximg.com/images/2891/DieHard200.jpg" } ], "url": "http://api.netflix.com/catalog/titles/movies/70111470", "Rating": 4.0, "Bookmark": [] }, { "id": 654356453, "title": "Bad Boys", "Boxarts": [{width:$, height:200, url: "Http://cdn-0.nflximg.com/images/2891/BadBoys200.jpg"}, {width:height:200, url: "Http://cdn-0.nflximg.com/images/2891/BadBoys150.jpg" } ], "url": "http://api.netflix.com/catalog/titles/movies/70111470", "Rating": 5.0, "Bookmark": [{id:432534, time:65876586}]}]}, {name:"New releases", Videos: [{"id": 65432445, "title": "The Chamber", "Boxarts": [{width:height:200, url: "Http://cdn-0.nflximg.com/images/2891/TheChamber150.jpg"}, {width:$, height:200, url: "Http://cdn-0.nflximg.com/images/2891/TheChamber200.jpg" } ], "url": "http://api.netflix.com/catalog/titles/movies/70111470", "Rating": 4.0, "Bookmark": [] }, { "id": 675465, "title": "Fracture", "Boxarts": [{width:$, height:200, url: "Http://cdn-0.nflximg.com/images/2891/Fracture200.jpg"}, {width:height:200, url: "Http://cdn-0.nflximg.com/images/2891/Fracture150.jpg"}, {width:height:200, url: "Http://cdn-0.nflximg.com/images/2891/Fracture300.jpg" } ], "url": "http://api.netflix.com/catalog/titles/movies/70111470", "Rating": 5.0, "Bookmark": [{id:432534, time:65876586 }] } ] } ]; //Use one or more maps, Concatall, and filter calls to create a array with the following items // [ //{"id": 675465, "title": "Fracture", "boxart": "Http://cdn-0.nflximg.com/images/2891/Fracture150.jpg"}, //{"id": 65432445, "title": "The Chamber", "Boxart": "Http://cdn-0.nflximg.com/images/2891/TheChamber150.jpg"}, //{"id": 654356453, "title": "Bad Boys", "Boxart": "Http://cdn-0.nflximg.com/images/2891/BadBoys150.jpg"}, //{"id": 70111470, "title": "Die Hard", "boxart": "Http://cdn-0.nflximg.com/images/2891/DieHard150.jpg"} // ]; returnmovielists. Map (function(movielist) {returnMovieList.videos.map (function(video) {returnVideo.boxarts.filter (function(boxart) {returnBoxart.width = = 150; }). Map (function(boxart) {return{id:video.id, Title:video.title, Boxart:boxart.url}}) }). Concatall ()}). Concatall ()}
You need to make sure your got everything you need to display. So there is three level deep. Any apply n-1 Concatall.
[Javascript] Ex:concatall, map and filter