Skip to content

Commit 11ce5ca

Browse files
author
As'ad Saleh Umar
committed
feat: create flat-map-quiz
1 parent e75c885 commit 11ce5ca

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

flat-map-quiz.ts

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
const movieLists = [
2+
{
3+
name: "Instant Queue",
4+
videos: [
5+
{
6+
id: 70111470,
7+
title: "Die Hard",
8+
boxarts: [
9+
{
10+
width: 150,
11+
height: 200,
12+
url: "http://cdn-0.nflximg.com/images/2891/DieHard150.jpg",
13+
},
14+
{
15+
width: 200,
16+
height: 200,
17+
url: "http://cdn-0.nflximg.com/images/2891/DieHard200.jpg",
18+
},
19+
],
20+
url: "http://api.netflix.com/catalog/titles/movies/70111470",
21+
rating: 4.0,
22+
bookmark: [],
23+
},
24+
{
25+
id: 654356453,
26+
title: "Bad Boys",
27+
boxarts: [
28+
{
29+
width: 200,
30+
height: 200,
31+
url: "http://cdn-0.nflximg.com/images/2891/BadBoys200.jpg",
32+
},
33+
{
34+
width: 150,
35+
height: 200,
36+
url: "http://cdn-0.nflximg.com/images/2891/BadBoys150.jpg",
37+
},
38+
],
39+
url: "http://api.netflix.com/catalog/titles/movies/70111470",
40+
rating: 5.0,
41+
bookmark: [{ id: 432534, time: 65876586 }],
42+
},
43+
],
44+
},
45+
{
46+
name: "New Releases",
47+
videos: [
48+
{
49+
id: 65432445,
50+
title: "The Chamber",
51+
boxarts: [
52+
{
53+
width: 150,
54+
height: 200,
55+
url: "http://cdn-0.nflximg.com/images/2891/TheChamber150.jpg",
56+
},
57+
{
58+
width: 200,
59+
height: 200,
60+
url: "http://cdn-0.nflximg.com/images/2891/TheChamber200.jpg",
61+
},
62+
],
63+
url: "http://api.netflix.com/catalog/titles/movies/70111470",
64+
rating: 4.0,
65+
bookmark: [],
66+
},
67+
{
68+
id: 675465,
69+
title: "Fracture",
70+
boxarts: [
71+
{
72+
width: 200,
73+
height: 200,
74+
url: "http://cdn-0.nflximg.com/images/2891/Fracture200.jpg",
75+
},
76+
{
77+
width: 150,
78+
height: 200,
79+
url: "http://cdn-0.nflximg.com/images/2891/Fracture150.jpg",
80+
},
81+
{
82+
width: 300,
83+
height: 200,
84+
url: "http://cdn-0.nflximg.com/images/2891/Fracture300.jpg",
85+
},
86+
],
87+
url: "http://api.netflix.com/catalog/titles/movies/70111470",
88+
rating: 5.0,
89+
bookmark: [{ id: 432534, time: 65876586 }],
90+
},
91+
],
92+
},
93+
];
94+
95+
// Target: {id, title, boxart} with boxart size 150x200px.
96+
97+
interface Result {
98+
id: number;
99+
title: string;
100+
boxart: string;
101+
}
102+
103+
const result: Result[] = movieLists.flatMap((movieList) => {
104+
return movieList.videos.flatMap((video) => {
105+
return video.boxarts
106+
.filter((boxart) => {
107+
return boxart.width === 150 && boxart.height === 200;
108+
})
109+
.map((boxart) => ({
110+
id: video.id,
111+
title: video.title,
112+
boxart: boxart.url,
113+
}));
114+
});
115+
});
116+
117+
console.log(result);

0 commit comments

Comments
 (0)