forked from RochMoreau/secure-web-dev-workshop1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
168 lines (141 loc) · 5.01 KB
/
Copy pathindex.js
File metadata and controls
168 lines (141 loc) · 5.01 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Invoking strict mode https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#invoking_strict_mode
'use strict'
// https://opendata.paris.fr/explore/dataset/lieux-de-tournage-a-paris/information
const filmingLocations = require('./lieux-de-tournage-a-paris.json')
console.log('🚀 It Works!');
/**
* 💅 Try to produce the most readable code, use meaningful variable names
* Your intentions should be clear by just reading the code
* Good luck, have fun !
*/
// 📝 TODO: Number of filming locations
// 1. Make the function return the number of filming locations
function getFilmingLocationsNumber () {
const keyCount = Object.keys(filmingLocations).length;
return keyCount;
}
//console.log(`There are ${getFilmingLocationsNumber()} filming locations in Paris`)
// 📝 TODO: Filming locations sorted by start date, from most recent to oldest.
// 1. Implement the function
// 2. Log the first and last item in array
function sortFilmingLocationsByStartDate (filmArray) {
return filmArray.sort(function(a, b){
return a.fields.date_debut - b.fields.date_debut;
});
}
const resultat1 = sortFilmingLocationsByStartDate(filmingLocations);
//console.log(resultat1[0].fields.date_debut,resultat1[resultat1.length-1].fields.date_debut)
// 📝 TODO: Number of filming locations in 2020 only
// 1. Make the function return the number of filming locations in 2020 only
// 2. Log the result
function getFilmingLocationsNumber2020 (filmArray) {
const result= filmArray.map(function(film) {
if(film.fields.annee_tournage == 2020)
return film;
});
return sortFilmingLocationsByStartDate(result)
}
//console.log(getFilmingLocationsNumber2020(filmingLocations))
// 📝 TODO: Number of filming locations per year
// 1. Implement the function, the expected result is an object with years as
// keys and filming locations number as value, e.g:
// const filmingLocationsPerYear = {
// '2020': 1234,
// '2021': 1234,
// }
// 2. Log the result
function countFilmsByYear(){
let data = {}
for(let i = 0; i < filmingLocations.length-1; i++)
{
if (filmingLocations[i].fields.annee_tournage in data)
{
data[filmingLocations[i].fields.annee_tournage] += 1
}
else data[filmingLocations[i].fields.annee_tournage]=1
}
return data
}
console.log(countFilmsByYear())
// 📝 TODO: Number of filming locations by district (arrondissement)
// 1. Implement the function, the expected result is an object with
// district as keys and filming locations number as value, e.g:
// const filmingLocationsPerDistrict = {
// '75013': 1234,
// '75014': 1234,
// }
// 2. Log the result
function getFilmingLocationsNumberPerDistrict () {
return {}
}
console.log()
// 📝 TODO: Number of locations per film, sorted in descending order
// 1. Implement the function, result expected as an array of object like:
// const result = [{film: 'LRDM - Patriot season 2', locations: 12}, {...}]
// 2. Log the first and last item of the array
function getFilmLocationsByFilm () {
return []
}
console.log()
// 📝 TODO: Number of different films
// 1. Implement the function
// 2. Log the result
function getNumberOfFilms() {
return ''
}
// 📝 TODO: All the filming locations of `LRDM - Patriot season 2`
// 1. Return an array with all filming locations of LRDM - Patriot season 2
// 2. Log the result
function getArseneFilmingLocations () {
return []
}
// 📝 TODO: Tous les arrondissement des lieux de tournage de nos films favoris
// (favoriteFilms)
// 1. Return an array of all the districts of each favorite films given as a
// parameter. e.g. :
// const films = { 'LRDM - Patriot season 2': ['75013'] }
// 2. Log the result
function getFavoriteFilmsLocations (favoriteFilmsNames) {
return []
}
const favoriteFilms =
[
'LRDM - Patriot season 2',
'Alice NEVERS',
'Emily in Paris',
]
// 📝 TODO: All filming locations for each film
// e.g. :
// const films = {
// 'LRDM - Patriot season 2': [{...}],
// 'Une jeune fille qui va bien': [{...}]
// }
function getFilmingLocationsPerFilm () {
return { }
}
// 📝 TODO: Count each type of film (Long métrage, Série TV, etc...)
// 1. Implement the function
// 2. Log the result
function countFilmingTypes () {
return {}
}
// 📝 TODO: Sort each type of filming by count, from highest to lowest
// 1. Implement the function. It should return a sorted array of objects like:
// [{type: 'Long métrage', count: 1234}, {...}]
// 2. Log the result
function sortedCountFilmingTypes () {
return []
}
/**
* This arrow functions takes a duration in milliseconds and returns a
* human-readable string of the duration
* @param ms
* @returns string
*/
const duration = (ms) => `${(ms/(1000*60*60*24)).toFixed(0)} days, ${((ms/(1000*60*60))%24).toFixed(0)} hours and ${((ms/(1000*60))%60).toFixed(0)} minutes`
// 📝 TODO: Find the filming location with the longest duration
// 1. Implement the function
// 2. Log the filming location, and its computed duration
// 📝 TODO: Compute the average filming duration
// 1. Implement the function
// 2. Log the result