-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessing_releases.js
75 lines (62 loc) · 2.21 KB
/
processing_releases.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
**Problem**
Write a Function named processReleaseData that processes the following movie release data:
The Function should generate an Array of Objects that contain only the id and title key/value pairs.
You may assume that id and title, when existing, is an integer greater than 0 and non-empty string respectively.
Here are the rules:
- Keep only releases that have both id and title property present.
- Keep only the id and title data for each release.
**Examples / Test Cases**
function processReleaseData(data) {
// ...
}
processReleaseData(newReleases);
// should return:
[{ id: 70111470, title: 'Die Hard'}, { id: 675465, title: 'Fracture' }];
**Data Structures**
**Algorithm**
1. select using filter only releases without an id OR a title property
2. transorm using map to create a new array with objects only containing id and title pairs
*/
let 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,
'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 }],
},
{
'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 }],
},
];
function processReleaseData(data) {
let idAndtitle = data.filter(release => (release['id'] || release.id === 0) && release['title']);
return idAndtitle.map(release => shortenRelase(release));
}
function shortenRelase(release) {
return { id: release['id'], title: release['title'] };
}
console.log(processReleaseData(newReleases));
// should return:
// [{ id: 70111470, title: 'Die Hard'}, { id: 675465, title: 'Fracture' }];