Skip to content

Instantly share code, notes, and snippets.

@TCotton
Created August 12, 2017 18:55
Show Gist options
  • Save TCotton/2d33b3e7d1080b5c592f3abb628ea13d to your computer and use it in GitHub Desktop.
Save TCotton/2d33b3e7d1080b5c592f3abb628ea13d to your computer and use it in GitHub Desktop.
filter and map example
const 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
}]
}
];
const favoriteIds = newReleases
.filter(function(movie) {
return movie.rating === 5.0;
})
.map(function(movie) {
return movie.id;
});
console.dir(favoriteIds);
// [654356453, 675465];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment