Created
November 20, 2015 14:15
-
-
Save bsitruk/e8650c368a1a6c741978 to your computer and use it in GitHub Desktop.
Functional programming: join two arrays by a key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function() { | |
var lists = [ | |
{ | |
"id": 5434364, | |
"name": "New Releases" | |
}, | |
{ | |
"id": 65456475, | |
name: "Thrillers" | |
} | |
], | |
videos = [ | |
{ | |
"listId": 5434364, | |
"id": 65432445, | |
"title": "The Chamber" | |
}, | |
{ | |
"listId": 5434364, | |
"id": 675465, | |
"title": "Fracture" | |
}, | |
{ | |
"listId": 65456475, | |
"id": 70111470, | |
"title": "Die Hard" | |
}, | |
{ | |
"listId": 65456475, | |
"id": 654356453, | |
"title": "Bad Boys" | |
} | |
]; | |
return lists.map(function(list) { | |
return { | |
name: list.name, | |
videos: | |
videos. | |
filter(function(video) { | |
return video.listId === list.id; | |
}). | |
map(function(video) { | |
return {id: video.id, title: video.title}; | |
}) | |
}; | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment