From ae54f8eb438ffe636d2470d97b9643606132ef56 Mon Sep 17 00:00:00 2001 From: Llinares Laura Date: Tue, 20 Sep 2022 19:24:03 +0200 Subject: [PATCH 1/3] TD1 --- index.js | 87 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 9b48491..586d099 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,20 @@ 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 '' + let liste = filmingLocations.sort(function compareFn(a,b){return new Date(a.fields.date_debut) - new Date(b.fields.date_debut); }); + return liste.shift() } -console.log(``) +console.log('Filming location sorted by start date') +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 '' + let result = filmingLocations.filter( value => value.fields.annee_tournage == 2020 ); + return result.length } -console.log() +console.log('There are the number of filming locations in 2020 only : ' + getFilmingLocationsNumber2020()) // 📝 TODO: Number of filming locations per year // 1. Implement the function, the expected result is an object with years as @@ -44,9 +47,19 @@ console.log() // } // 2. Log the result function getFilmingLocationsNumberPerYear () { - return {} + let resultYear = filmingLocations; + let year = 2016; //dataset start in 2016 + let result = new Object(); + while (resultYear.length != 0 ) { + resultYear = filmingLocations.filter(value => value.fields.annee_tournage == year); + result[year] = resultYear.length; + year = year + 1; + } + + return result } -console.log() +console.log('Filming location number per year :') +console.log(getFilmingLocationsNumberPerYear()) // 📝 TODO: Number of filming locations by district (arrondissement) // 1. Implement the function, the expected result is an object with @@ -57,32 +70,71 @@ console.log() // } // 2. Log the result function getFilmingLocationsNumberPerDistrict () { - return {} + let ardt = 75001; + let result = new Object(); + while (ardt != 75021 ) { + let resultArdt = filmingLocations.filter(value => value.fields.ardt_lieu == ardt); + result[ardt] = resultArdt.length; + ardt = ardt + 1; + } + return result } -console.log() +console.log('Filming location number per district : ') +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 [] + var tabFilmNames = [] + filmingLocations.forEach(function(element){ + if (!tabFilmNames.includes(element.fields.nom_tournage)){ + tabFilmNames.push(element.fields.nom_tournage) + } + }) + var tab = [] + tabFilmNames.forEach(function(element){ + var dict = {"film":element,"locations":0} + filmingLocations.forEach(function(element1){ + if (element1.fields.nom_tournage == element){ + dict["locations"]++ + } + }) + tab.push(dict) + }) + const result = tab.sort(function(a,b){return b['locations']-a['locations']}) + return result } -console.log() +const result = getFilmLocationsByFilm() +console.log(result[0],result[result.length-1]) + // 📝 TODO: Number of different films // 1. Implement the function // 2. Log the result function getNumberOfFilms() { - return '' + return getFilmLocationsByFilm().length } +console.log('Number of film : ' + getNumberOfFilms()) // 📝 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 [] + let result = new Array(); + let l = filmingLocations.filter(v => v.fields.nom_tournage == 'LRDM - Patriot season 2'); + let i = 0; + while (i != l.length-1) { + result.push(l[i].fields.adresse_lieu); + i = i+1; + } + return result + + } +console.log('TODO: All the filming locations of LRDM - Patriot season 2') +console.log(getArseneFilmingLocations()) // 📝 TODO: Tous les arrondissement des lieux de tournage de nos films favoris // (favoriteFilms) @@ -91,7 +143,14 @@ function getArseneFilmingLocations () { // const films = { 'LRDM - Patriot season 2': ['75013'] } // 2. Log the result function getFavoriteFilmsLocations (favoriteFilmsNames) { - return [] + let result = new Array(); + let l = filmingLocations.filter(v => v.fields.nom_tournage == favoriteFilmsNames); + let i = 0; + while (i != l.length-1) { + result.push(l[i].fields.ardt); + i = i+1; + } + return result } const favoriteFilms = [ From c581a037abb8c6b9d9620e55a713eacb47f90402 Mon Sep 17 00:00:00 2001 From: Llinares Laura Date: Wed, 21 Sep 2022 17:37:58 +0200 Subject: [PATCH 2/3] TD1 --- index.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 586d099..3a34294 100644 --- a/index.js +++ b/index.js @@ -133,7 +133,7 @@ function getArseneFilmingLocations () { } -console.log('TODO: All the filming locations of LRDM - Patriot season 2') +console.log('All the filming locations of LRDM - Patriot season 2') console.log(getArseneFilmingLocations()) // 📝 TODO: Tous les arrondissement des lieux de tournage de nos films favoris @@ -144,20 +144,30 @@ console.log(getArseneFilmingLocations()) // 2. Log the result function getFavoriteFilmsLocations (favoriteFilmsNames) { let result = new Array(); - let l = filmingLocations.filter(v => v.fields.nom_tournage == favoriteFilmsNames); - let i = 0; - while (i != l.length-1) { - result.push(l[i].fields.ardt); + let resultb = new Object(); + for (let i=0; i < favoriteFilmsNames.length; i++) { + let l = filmingLocations.filter(v => v.fields.nom_tournage == favoriteFilmsNames[i]); + let cpt = 0; + while (cpt != l.length-1){ + resultb[favoriteFilmsNames[i]] = l[cpt].fields.ardt_lieu; + result.push(resultb); + cpt = cpt + 1; + } + result = result.filter((x, i) => result.indexOf(x) === i); // éliminer les doublons i = i+1; } return result } +//alice nevers il trouve pas ?? à régler + const favoriteFilms = [ 'LRDM - Patriot season 2', 'Alice NEVERS', 'Emily in Paris', ] +console.log(getFavoriteFilmsLocations(favoriteFilms)) + // 📝 TODO: All filming locations for each film // e.g. : From 26ee83ec5514539f702746a0f63b6aa62c847fa1 Mon Sep 17 00:00:00 2001 From: Llinares Laura Date: Wed, 21 Sep 2022 17:58:54 +0200 Subject: [PATCH 3/3] TD1 --- index.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 3a34294..05fb465 100644 --- a/index.js +++ b/index.js @@ -87,15 +87,15 @@ console.log(getFilmingLocationsNumberPerDistrict()) // const result = [{film: 'LRDM - Patriot season 2', locations: 12}, {...}] // 2. Log the first and last item of the array function getFilmLocationsByFilm () { - var tabFilmNames = [] + let tabFilmNames = [] filmingLocations.forEach(function(element){ if (!tabFilmNames.includes(element.fields.nom_tournage)){ tabFilmNames.push(element.fields.nom_tournage) } }) - var tab = [] + let tab = [] tabFilmNames.forEach(function(element){ - var dict = {"film":element,"locations":0} + let dict = {"film":element,"locations":0} filmingLocations.forEach(function(element1){ if (element1.fields.nom_tournage == element){ dict["locations"]++ @@ -166,6 +166,8 @@ const favoriteFilms = 'Alice NEVERS', 'Emily in Paris', ] + +console.log('Tous les arrondissement des lieux de tournage de nos films favoris') console.log(getFavoriteFilmsLocations(favoriteFilms)) @@ -176,24 +178,69 @@ console.log(getFavoriteFilmsLocations(favoriteFilms)) // 'Une jeune fille qui va bien': [{...}] // } function getFilmingLocationsPerFilm () { - return { } + let tabFilmNames = [] + filmingLocations.forEach(function(element){ + if (!tabFilmNames.includes(element.fields.nom_tournage)){ + tabFilmNames.push(element.fields.nom_tournage) + } + }) + let tab = [] + tabFilmNames.forEach(function(element){ + let dict = {"film":element,"locations":[]} + filmingLocations.forEach(function(element1){ + if (element1.fields.nom_tournage == element){ + dict["locations"].push(element1.fields.adresse_lieu); + } + }) + tab.push(dict); + }) + return tab[0]; } +console.log('All filming locations for each film : ') +console.log(getFilmingLocationsPerFilm()) // 📝 TODO: Count each type of film (Long métrage, Série TV, etc...) // 1. Implement the function // 2. Log the result function countFilmingTypes () { - return {} + let tabTypeFilm = [] + filmingLocations.forEach(function(element){ + if (!tabTypeFilm.includes(element.fields.type_tournage)){ + tabTypeFilm.push(element.fields.type_tournage) + } + }) + let tab = [] + tabTypeFilm.forEach(function(element){ + let dict = {"type":element,"count":0} + filmingLocations.forEach(function(element1){ + if (element1.fields.type_tournage == element){ + dict["count"]++; + } + }) + tab.push(dict); + }) + return tab; } +console.log('Count each type of film (Long métrage, Série TV, etc...) : ') +console.log(countFilmingTypes()); + + // 📝 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 [] +function sortedCountFilmingTypes (liste) { + liste.sort(function(a,b){return b['count']-a['count']}); + return liste } +console.log('Sort each type of filming by count, from highest to lowest : ') +console.log(sortedCountFilmingTypes(countFilmingTypes())); + + + + /** * This arrow functions takes a duration in milliseconds and returns a * human-readable string of the duration