diff --git a/index.js b/index.js index 9b48491..61b6bdc 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,7 @@ console.log('πŸš€ It Works!'); // πŸ“ TODO: Number of filming locations // 1. Make the function return the number of filming locations function getFilmingLocationsNumber () { - return '' + return filmingLocations.length; } console.log(`There is ${getFilmingLocationsNumber()} filming locations in Paris`) @@ -23,17 +23,22 @@ console.log(`There is ${getFilmingLocationsNumber()} filming locations in Paris` // 1. Implement the function // 2. Log the first and last item in array function sortFilmingLocationsByStartDate () { - return '' + const tab = filmingLocations.sort((a,b) => (a.fields.date_debut>b.fields.date_debut) ? 1:-1); + return tab; + } -console.log(``) +//console.log(sortFilmingLocationsByStartDate()); +//console.log(sortFilmingLocationsByStartDate()) // πŸ“ 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 () { - return '' + const tab = filmingLocations.filter((player) => player.fields.annee_tournage == 2020); + return tab.length; + } -console.log() +console.log(getFilmingLocationsNumber2020()) // πŸ“ TODO: Number of filming locations per year // 1. Implement the function, the expected result is an object with years as @@ -44,9 +49,15 @@ console.log() // } // 2. Log the result function getFilmingLocationsNumberPerYear () { - return {} + let counter = {} + + filmingLocations.forEach(function(obj) { + var key = obj.fields.annee_tournage + counter[key] = (counter[key] || 0) + 1 + }) + return counter } -console.log() +console.log(getFilmingLocationsNumberPerYear()) // πŸ“ TODO: Number of filming locations by district (arrondissement) // 1. Implement the function, the expected result is an object with @@ -57,33 +68,64 @@ console.log() // } // 2. Log the result function getFilmingLocationsNumberPerDistrict () { - return {} + let counter = {} + + filmingLocations.forEach(function(obj) { + var key = obj.fields.ardt_lieu + counter[key] = (counter[key] || 0) + 1 + }) + return counter } -console.log() +console.log(getFilmingLocationsNumberPerDistrict()) // πŸ“ 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 [] + let counter = {} + for (var i=0; i `${(ms/(1000*60*60*24)).toFixed(0)} days, ${((ms/(1000* // 1. Implement the function // 2. Log the filming location, and its computed duration +function filmingLocationLongestDuration() { + let ans = 0, nomTournage = ""; + for (let i of filmingLocations) { + let key = i.fields; + let d1 = new Date(key.date_fin); + let d2 = new Date(key.date_debut); + let d3 = d1.getTime()-d2.getTime() + if (ans