@@ -12,30 +12,30 @@ console.log('🚀 It Works!');
1212 * Good luck, have fun !
1313 */
1414
15- // 📝 TODO: Number of filming locations
15+ // 1 📝 TODO: Number of filming locations
1616// 1. Make the function return the number of filming locations
1717function getFilmingLocationsNumber ( ) {
1818 return filmingLocations . length
1919}
20- console . log ( `There is ${ getFilmingLocationsNumber ( ) } filming locations in Paris` )
20+ // console.log(`There is ${getFilmingLocationsNumber()} filming locations in Paris`)
2121
22- // 📝 TODO: Filming locations sorted by start date, from most recent to oldest.
22+ // 2 📝 TODO: Filming locations sorted by start date, from most recent to oldest.
2323// 1. Implement the function
2424// 2. Log the first and last item in array
2525function sortFilmingLocationsByStartDate ( ) {
2626 const sorted = filmingLocations . sort ( ( a , b ) => new Date ( b . fields . date_debut ) - new Date ( a . fields . date_debut ) )
27- return sorted [ sorted . length - 1 ]
27+ return sorted
2828}
29- console . log ( )
29+ // console.log(sortFilmingLocationsByStartDate()[0] )
3030
31- // 📝 TODO: Number of filming locations in 2020 only
31+ // 3 📝 TODO: Number of filming locations in 2020 only
3232// 1. Make the function return the number of filming locations in 2020 only
3333// 2. Log the result
3434function getFilmingLocationsNumber2020 ( ) {
3535 const result = filmingLocations . filter ( location => new Date ( location . fields . date_debut ) . getFullYear ( ) == 2020 ) ;
3636 return result
3737}
38- console . log ( )
38+ // console.log(getFilmingLocationsNumber2020() )
3939
4040// 📝 TODO: Number of filming locations per year
4141// 1. Implement the function, the expected result is an object with years as
@@ -53,9 +53,9 @@ function getFilmingLocationsNumberPerYear () {
5353 }
5454 return { res}
5555}
56- console . log ( )
56+ // console.log(getFilmingLocationsNumberPerYear() )
5757
58- // 📝 TODO: Number of filming locations by district (arrondissement)
58+ // 4 📝 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 = {
@@ -71,30 +71,63 @@ function getFilmingLocationsNumberPerDistrict () {
7171 }
7272 return { res}
7373}
74- console . log ( getFilmingLocationsNumberPerDistrict ( ) )
74+ // console.log(getFilmingLocationsNumberPerDistrict())
7575
76- // 📝 TODO: Number of locations per film, sorted in descending order
76+ // 5 📝 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
8080function getFilmLocationsByFilm ( ) {
81- return [ ]
81+ var res = [ ]
82+ var tournage = { }
83+ for ( let element in filmingLocations ) {
84+ let film = filmingLocations [ element ] . fields . nom_tournage
85+ let temp = res . find ( el => el . film == film )
86+ if ( temp ) {
87+ temp . locations = temp . locations + 1
88+ }
89+ else {
90+ tournage . film = film
91+ tournage . locations = 1
92+ res . push ( { ...tournage } )
93+ }
94+ }
95+ res = res . sort ( ( a , b ) => b . locations - a . locations )
96+ return res
8297}
83- console . log ( )
98+ //console.log(getFilmLocationsByFilm()[0])
99+ //console.log(getFilmLocationsByFilm()[getFilmLocationsByFilm().length-1])
84100
85- // 📝 TODO: Number of different films
101+ // 6 📝 TODO: Number of different films
86102// 1. Implement the function
87103// 2. Log the result
88104function getNumberOfFilms ( ) {
89- return ''
105+ var compt = [ ]
106+ var res = 0
107+ for ( let i = 0 ; i < filmingLocations . length ; i ++ ) {
108+ var temp = filmingLocations [ i ] . fields . nom_tournage
109+ if ( ! ( compt . includes ( temp ) ) ) {
110+ res += 1
111+ compt . push ( temp )
112+ }
113+ }
114+ return res
90115}
116+ // console.log(getNumberOfFilms())
91117
92- // 📝 TODO: All the filming locations of `LRDM - Patriot season 2`
118+ // 7 📝 TODO: All the filming locations of `LRDM - Patriot season 2`
93119// 1. Return an array with all filming locations of LRDM - Patriot season 2
94120// 2. Log the result
95121function getArseneFilmingLocations ( ) {
96- return [ ]
122+ 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 )
126+ }
127+ }
128+ return res
97129}
130+ console . log ( getArseneFilmingLocations ( ) )
98131
99132// 📝 TODO: Tous les arrondissement des lieux de tournage de nos films favoris
100133// (favoriteFilms)
0 commit comments