Skip to content

Commit c60d538

Browse files
committed
exo jusqu'au 12 faits
1 parent 98cc0df commit c60d538

File tree

1 file changed

+57
-27
lines changed

1 file changed

+57
-27
lines changed

index.js

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function getFilmingLocationsNumber2020 () {
3737
}
3838
//console.log(getFilmingLocationsNumber2020())
3939

40-
// 📝 TODO: Number of filming locations per year
40+
// 4 📝 TODO: Number of filming locations per year
4141
// 1. Implement the function, the expected result is an object with years as
4242
// keys and filming locations number as value, e.g:
4343
// const filmingLocationsPerYear = {
@@ -46,16 +46,16 @@ function getFilmingLocationsNumber2020 () {
4646
// }
4747
// 2. Log the result
4848
function getFilmingLocationsNumberPerYear () {
49-
var res = {}
49+
const filmingLocationsPerYear = {}
5050
for(let element in filmingLocations){
5151
let year = new Date(filmingLocations[element].fields.date_debut).getFullYear()
52-
res[year] = (res[year]+1) || 1 ;
52+
filmingLocationsPerYear[year] = (filmingLocationsPerYear[year]+1) || 1 ;
5353
}
54-
return {res}
54+
return filmingLocationsPerYear
5555
}
5656
//console.log(getFilmingLocationsNumberPerYear())
5757

58-
// 4 📝 TODO: Number of filming locations by district (arrondissement)
58+
// 5 📝 TODO: Number of filming locations by district (arrondissement)
5959
// 1. Implement the function, the expected result is an object with
6060
// district as keys and filming locations number as value, e.g:
6161
// const filmingLocationsPerDistrict = {
@@ -64,16 +64,16 @@ function getFilmingLocationsNumberPerYear () {
6464
// }
6565
// 2. Log the result
6666
function getFilmingLocationsNumberPerDistrict () {
67-
var res = {}
67+
const filmingLocationsPerDistrict = {}
6868
for(let element in filmingLocations){
6969
let district = filmingLocations[element].fields.ardt_lieu
70-
res[district] = (res[district]+1) || 1 ;
70+
filmingLocationsPerDistrict[district] = (filmingLocationsPerDistrict[district]+1) || 1 ;
7171
}
72-
return {res}
72+
return filmingLocationsPerDistrict
7373
}
7474
//console.log(getFilmingLocationsNumberPerDistrict())
7575

76-
// 5 📝 TODO: Number of locations per film, sorted in descending order
76+
// 6 📝 TODO: Number of locations per film, sorted in descending order
7777
// 1. Implement the function, result expected as an array of object like:
7878
// const result = [{film: 'LRDM - Patriot season 2', locations: 12}, {...}]
7979
// 2. Log the first and last item of the array
@@ -98,7 +98,7 @@ function getFilmLocationsByFilm () {
9898
//console.log(getFilmLocationsByFilm()[0])
9999
//console.log(getFilmLocationsByFilm()[getFilmLocationsByFilm().length-1])
100100

101-
// 6 📝 TODO: Number of different films
101+
// 7 📝 TODO: Number of different films
102102
// 1. Implement the function
103103
// 2. Log the result
104104
function getNumberOfFilms() {
@@ -115,21 +115,21 @@ function getNumberOfFilms() {
115115
}
116116
// console.log(getNumberOfFilms())
117117

118-
// 7 📝 TODO: All the filming locations of `LRDM - Patriot season 2`
118+
// 8 📝 TODO: All the filming locations of `LRDM - Patriot season 2`
119119
// 1. Return an array with all filming locations of LRDM - Patriot season 2
120120
// 2. Log the result
121121
function getArseneFilmingLocations () {
122122
var res = []
123-
for (let i=0; i < filmingLocations.length; i++){
124-
if(filmingLocations[i].fields.nom_tournage == 'LRDM - Patriot season 2'){
125-
res.push(filmingLocations[i].fields.adresse_lieu)
123+
for (let element in filmingLocations){
124+
if(filmingLocations[element].fields.nom_tournage == 'LRDM - Patriot season 2'){
125+
res.push(filmingLocations[element].fields.adresse_lieu)
126126
}
127127
}
128128
return res
129129
}
130-
//console.log(getArseneFilmingLocations())
130+
console.log(getArseneFilmingLocations())
131131

132-
// 8 📝 TODO: Tous les arrondissement des lieux de tournage de nos films favoris
132+
// 9 📝 TODO: Tous les arrondissement des lieux de tournage de nos films favoris
133133
// (favoriteFilms)
134134
// 1. Return an array of all the districts of each favorite films given as a
135135
// parameter. e.g. :
@@ -143,7 +143,7 @@ const favoriteFilms =
143143
]
144144

145145
function getFavoriteFilmsLocations (favoriteFilmsNames) {
146-
var res = []
146+
const res = []
147147
for (let j = 0 ; j < favoriteFilmsNames.length ; j++){
148148
let film = favoriteFilmsNames[j]
149149
for(let i=0 ; i < filmingLocations.length ; i++) {
@@ -161,33 +161,63 @@ function getFavoriteFilmsLocations (favoriteFilmsNames) {
161161
}
162162
return res
163163
}
164-
console.log(getFavoriteFilmsLocations(favoriteFilms))
164+
//console.log(getFavoriteFilmsLocations(favoriteFilms))
165165

166-
// 📝 TODO: All filming locations for each film
166+
// 10 📝 TODO: All filming locations for each film
167167
// e.g. :
168168
// const films = {
169169
// 'LRDM - Patriot season 2': [{...}],
170170
// 'Une jeune fille qui va bien': [{...}]
171171
// }
172172
function getFilmingLocationsPerFilm () {
173-
return { }
173+
const res = {}
174+
for (let i = 0 ; i < filmingLocations.length ; i++){
175+
let film=filmingLocations[i].fields.nom_tournage
176+
let location=filmingLocations[i].fields.adresse_lieu
177+
if(res[film]){
178+
res[film].push(location)
179+
}
180+
else{
181+
res[film]= [location]
182+
}
183+
}
184+
return res
174185
}
186+
//console.log(getFilmingLocationsPerFilm()['LRDM - Patriot season 2'])
175187

176-
// 📝 TODO: Count each type of film (Long métrage, Série TV, etc...)
188+
// 11 📝 TODO: Count each type of film (Long métrage, Série TV, etc...)
177189
// 1. Implement the function
178190
// 2. Log the result
179191
function countFilmingTypes () {
180-
return {}
192+
var res = {}
193+
for(let element in filmingLocations){
194+
let type = filmingLocations[element].fields.type_tournage
195+
res[type] = (res[type]+1) || 1 ;
196+
}
197+
return {res}
181198
}
199+
//console.log(countFilmingTypes())
182200

183-
// 📝 TODO: Sort each type of filming by count, from highest to lowest
201+
// 12 📝 TODO: Sort each type of filming by count, from highest to lowest
184202
// 1. Implement the function. It should return a sorted array of objects like:
185203
// [{type: 'Long métrage', count: 1234}, {...}]
186204
// 2. Log the result
187205
function sortedCountFilmingTypes () {
188-
return []
206+
var res = []
207+
let count = countFilmingTypes()
208+
for(let element in filmingLocations){
209+
let typetournage = filmingLocations[element].fields.type_tournage
210+
let temp = res.find(el => el.type == typetournage)
211+
if(temp){
212+
temp.count +=1
213+
}
214+
else{
215+
res.push({type : typetournage, count : 1})
216+
}
217+
}
218+
return res
189219
}
190-
220+
//console.log(sortedCountFilmingTypes())
191221
/**
192222
* This arrow functions takes a duration in milliseconds and returns a
193223
* human-readable string of the duration
@@ -196,10 +226,10 @@ function sortedCountFilmingTypes () {
196226
*/
197227
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`
198228

199-
// 📝 TODO: Find the filming location with the longest duration
229+
// 13 📝 TODO: Find the filming location with the longest duration
200230
// 1. Implement the function
201231
// 2. Log the filming location, and its computed duration
202232

203-
// 📝 TODO: Compute the average filming duration
233+
// 14 📝 TODO: Compute the average filming duration
204234
// 1. Implement the function
205235
// 2. Log the result

0 commit comments

Comments
 (0)