From a8a0fc07cd72f1ceac2fe69e841a3b05bc201ed6 Mon Sep 17 00:00:00 2001 From: planbei Date: Wed, 21 Dec 2022 15:50:56 +0100 Subject: [PATCH 1/2] Secure web --- index.js | 131 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 114 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 9b48491..dd3d88c 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,28 @@ 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 comparison = (elemA, elemB) => new Date(elemA["fields"]["date_debut"]) - new Date(elemB["fields"]["date_debut"]) + return filmingLocations.sort(comparison) + } -console.log(``) +// let temparray = sortFilmingLocationsByStartDate() +// console.log(temparray[0],temparray[10000]) // πŸ“ 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 count = 0 + const tab = [] + for(const elem of filmingLocations) { + if( elem["fields"]["annee_tournage"]==="2020" && !(tab.find(x => x === elem["fields"]["adresse_lieu"] ))) { + tab.push(elem["fields"]["adresse_lieu"]); + count++; + } + } + return count; } -console.log() +console.log("The number of filming locations in 2020 is ",getFilmingLocationsNumber2020()) // πŸ“ TODO: Number of filming locations per year // 1. Implement the function, the expected result is an object with years as @@ -44,9 +55,24 @@ console.log() // } // 2. Log the result function getFilmingLocationsNumberPerYear () { - return {} + const filmingLocationsPerYear = {} + const result = {} + for (const elem of filmingLocations){ + if (filmingLocationsPerYear[elem["fields"]["annee_tournage"]] === undefined ) { + + filmingLocationsPerYear[elem["fields"]["annee_tournage"]] = [elem["fields"]["adresse_lieu"]]; + result[elem["fields"]["annee_tournage"]] = 1; + + } else if( !( filmingLocationsPerYear[elem["fields"]["annee_tournage"]].find(x => x === elem["fields"]["adresse_lieu"]) ) ) { + + filmingLocationsPerYear[elem["fields"]["annee_tournage"]].push(elem["fields"]["adresse_lieu"]); + result[elem["fields"]["annee_tournage"]] += 1; + + } + } + return result; } -console.log() +console.log(getFilmingLocationsNumberPerYear()) // πŸ“ TODO: Number of filming locations by district (arrondissement) // 1. Implement the function, the expected result is an object with @@ -56,42 +82,99 @@ console.log() // '75014': 1234, // } // 2. Log the result -function getFilmingLocationsNumberPerDistrict () { - return {} +function getFilmingLocationsNumberPerDistrict() { + const filmingLocationsPerDistrict = {} + const result = {} + for (const elem of filmingLocations){ + if (filmingLocationsPerDistrict[elem["fields"]["ardt_lieu"]] === undefined ) { + + filmingLocationsPerDistrict[elem["fields"]["ardt_lieu"]] = [elem["fields"]["adresse_lieu"]]; + result[elem["fields"]["ardt_lieu"]] = 1; + + } else if( !( filmingLocationsPerDistrict[elem["fields"]["ardt_lieu"]].find(x => x === elem["fields"]["adresse_lieu"]) ) ) { + + filmingLocationsPerDistrict[elem["fields"]["ardt_lieu"]].push(elem["fields"]["adresse_lieu"]); + result[elem["fields"]["ardt_lieu"]] += 1; + + } + } + return result; } -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 [] + + const result = [] + + for (const film of filmingLocations){ + + let alreadyInserted = false + for (const elem of result){ + if (elem['film'] === film["fields"]["nom_tournage"]) { + elem['locations'] += 1 + alreadyInserted = true + break + } + } + if (!alreadyInserted) { + result.push({'film':film["fields"]["nom_tournage"], 'locations':1}); + } + } + const condition = (a,b) => b['locations'] - a['locations'] + result.sort(condition) + return result; } -console.log() + +let nbLocationsPerFilm = getFilmLocationsByFilm() +console.log(nbLocationsPerFilm[0],nbLocationsPerFilm[nbLocationsPerFilm.length-1]) // πŸ“ TODO: Number of different films // 1. Implement the function // 2. Log the result function getNumberOfFilms() { - return '' + return nbLocationsPerFilm.length } +console.log("number of different movies :",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 locations = [] + for(const elem of filmingLocations) { + if(elem["fields"]["nom_tournage"]==="LRDM - Patriot season 2") { + locations.push(elem["fields"]["adresse_lieu"]) + } + } + return locations } +console.log("Adresses pour LRDM - Patriot season 2",getArseneFilmingLocations()) + // πŸ“ 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 [] +function getFavoriteFilmsLocations(favoriteFilmsNames) { + let result = [] + for(const elem of favoriteFilmsNames) { + result.push({"film":elem,"locations":[]}) + } + for(const elem of filmingLocations) { + for(const film of result) { + if(elem["fields"]["nom_tournage"]===film["film"] && !(film["locations"].find(x => x === elem["fields"]["ardt_lieu"]))) { + film["locations"].push(elem["fields"]["ardt_lieu"]) + break + } + } + } + return result } const favoriteFilms = [ @@ -100,6 +183,8 @@ const favoriteFilms = 'Emily in Paris', ] +console.log("Locations of our favorite films :", getFavoriteFilmsLocations(favoriteFilms)) + // πŸ“ TODO: All filming locations for each film // e.g. : // const films = { @@ -107,7 +192,19 @@ const favoriteFilms = // 'Une jeune fille qui va bien': [{...}] // } function getFilmingLocationsPerFilm () { - return { } + let result = [] + for(const elem of filmingLocations) { + result.push({"film":elem,"locations":[]}) + } + for(const elem of filmingLocations) { + for(const film of result) { + if(elem["fields"]["nom_tournage"]===film["film"]) { + film["locations"].push(elem["fields"]["adresse_lieu"]) + break + } + } + } + return result } // πŸ“ TODO: Count each type of film (Long mΓ©trage, SΓ©rie TV, etc...) From 9f568bdad740755825069c714bbc82c3f81812f7 Mon Sep 17 00:00:00 2001 From: planbei Date: Sat, 4 Feb 2023 20:21:13 +0100 Subject: [PATCH 2/2] Lol --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index dd3d88c..3952b2a 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ // 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!'); +console.log('πŸš€ It Works! Late'); /** * πŸ’… Try to produce the most readable code, use meaningful variable names