Quick actions

cmd+k|ctrl+k

Navigation

Languages

Projecting Arrays

Snippet info

Language

JavaScript

Visibility

public

Author

peter

Created

2016-04-24T15:26:47Z

Updated

2016-05-15T04:57:46Z

// Projection refers to the process of applying a function to a value and creating a new value
// For each video, add a projected {id, title} pair to the videoAndTitlePairs array.
var movieIdAndTitle = function projectionArray() {
	var newReleases = [
		{
			"id": 70111470,
			"title": "Die Hard",
			"boxart": "http://cdn-0.nflximg.com/images/2891/DieHard.jpg",
			"uri": "http://api.netflix.com/catalog/titles/movies/70111470",
			"rating": [4.0],
			"bookmark": []
		},
		{
			"id": 654356453,
			"title": "Bad Boys",
			"boxart": "http://cdn-0.nflximg.com/images/2891/BadBoys.jpg",
			"uri": "http://api.netflix.com/catalog/titles/movies/70111470",
			"rating": [5.0],
			"bookmark": [{ id:432534, time:65876586 }]
		},
		{
			"id": 65432445,
			"title": "The Chamber",
			"boxart": "http://cdn-0.nflximg.com/images/2891/TheChamber.jpg",
			"uri": "http://api.netflix.com/catalog/titles/movies/70111470",
			"rating": [4.0],
			"bookmark": []
		},
		{
			"id": 675465,
			"title": "Fracture",
			"boxart": "http://cdn-0.nflximg.com/images/2891/Fracture.jpg",
			"uri": "http://api.netflix.com/catalog/titles/movies/70111470",
			"rating": [5.0],
			"bookmark": [{
			    id:432534,
			    time:65876586
			}]
		}
	],
	videoAndTitlePairs = []; // accumulator
    
  newReleases.forEach(function(video) {
      videoAndTitlePairs.push({
          id: video.id,
          title: video.title
      });
  });
  return videoAndTitlePairs;
};

console.log(movieIdAndTitle());

	// ------------ INSERT CODE HERE! -----------------------------------
	// Use forEach function to accumulate {id, title} pairs from each video.
	// Put the results into the videoAndTitlePairs array using the Array's
	// push() method. Example: videoAndTitlePairs.push(newItem);
	// ------------ INSERT CODE HERE! -----------------------------------

	
	
INFO