arrays - Combining filter() and map () methods in javascript -
i have been working through study guide on github , trying work through problem chains filter , map answer. so, have array , i'm supposed use 2 methods select ids of videos rating of 5.0. here's array:
function() { 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 }] } ];
now code follows:
newreleases.filter(function(video){ return video.rating == 5.0; }).map (function(video) { return { id: video.id } }); }
my thought process first call filter method , apply test (video.rating == 5.0) , return elements pass test. use map method apply function elements passed test return want, ids of videos have 5.0 rating, having map return 'video.id'. when execute, error:
typeerror: 'undefined' not object (evaluating 'videoids.sortby')
this error code throwing me off, because don't see 'videoids
' variable in array , doesn't appear need apply .sortby
.
so asking clarification on error code please. have tried code in number of different fashions , have not come correct one, appreciate walk through of not doing. reason feel confident in code because have applied similar code similar exercise in [eloquent javascript] @ end of chapter 5 (exercise 5.2 mother-child age difference). have spent hours (more i'd admit) stuck on , have browsed stack overflow 2 hours. press answer button afraid won't learn doing that.
could please assist me?
please add return
. otherwise undefined
returning.
return newreleases.filter(function(video) { //...
Comments
Post a Comment