From a07307e7b1940b22816c26a49f6c9bd2adaae36c Mon Sep 17 00:00:00 2001 From: cowbra <32939303+cowbra@users.noreply.github.com> Date: Mon, 19 Sep 2022 17:49:56 +0200 Subject: [PATCH 1/5] Seance2.1 --- index.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 9b48491..6362318 100644 --- a/index.js +++ b/index.js @@ -15,25 +15,34 @@ console.log('🚀 It Works!'); // 📝 TODO: Number of filming locations // 1. Make the function return the number of filming locations function getFilmingLocationsNumber () { - return '' + const keyCount = Object.keys(filmingLocations).length; + return keyCount; } console.log(`There is ${getFilmingLocationsNumber()} filming locations in Paris`) // 📝 TODO: Filming locations sorted by start date, from most recent to oldest. // 1. Implement the function // 2. Log the first and last item in array -function sortFilmingLocationsByStartDate () { - return '' +function sortFilmingLocationsByStartDate (filmArray) { + return filmArray.sort(function(a, b){ + return a.fields.date_debut - b.fields.date_debut; + }); } -console.log(``) +const resultat1 = sortFilmingLocationsByStartDate(filmingLocations); +console.log(resultat1[0].fields.date_debut,resultat1[resultat1.length-1].fields.date_debut) // 📝 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 '' +function getFilmingLocationsNumber2020 (filmArray) { + + const result= filmArray.map(function(film) { + if(film.fields.annee_tournage == 2020) + return film; + }); + return sortFilmingLocationsByStartDate(result) } -console.log() +console.log(getFilmingLocationsNumber2020(filmingLocations)) // 📝 TODO: Number of filming locations per year // 1. Implement the function, the expected result is an object with years as From 46d62db4251e45719e95afd34cd166bf43445526 Mon Sep 17 00:00:00 2001 From: cowbra <32939303+cowbra@users.noreply.github.com> Date: Mon, 19 Sep 2022 17:53:07 +0200 Subject: [PATCH 2/5] seance2.2 --- index.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6362318..5976a40 100644 --- a/index.js +++ b/index.js @@ -34,6 +34,7 @@ console.log(resultat1[0].fields.date_debut,resultat1[resultat1.length-1].fields. // 📝 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 (filmArray) { const result= filmArray.map(function(film) { @@ -43,6 +44,9 @@ function getFilmingLocationsNumber2020 (filmArray) { return sortFilmingLocationsByStartDate(result) } console.log(getFilmingLocationsNumber2020(filmingLocations)) +*/ + + // 📝 TODO: Number of filming locations per year // 1. Implement the function, the expected result is an object with years as @@ -52,10 +56,31 @@ console.log(getFilmingLocationsNumber2020(filmingLocations)) // '2021': 1234, // } // 2. Log the result + +function getnumberfilmofyear(year) +{ + const filmsOfYears= filmingLocations.map(function(film) { + if(film.fields.annee_tournage == year) + return film; + }); + + const numberfilmsofYear = Object.keys(filmsOfYears).length; + return JSON.parse(year,numberfilmsofYear); +} + + + + function getFilmingLocationsNumberPerYear () { - return {} + let jsonArrayResult = {} + + + + return result; } -console.log() + + +console.log(getnumberfilmofyear(2020)) // 📝 TODO: Number of filming locations by district (arrondissement) // 1. Implement the function, the expected result is an object with From 8dfd7879bb584791f9c2e9ea951ff70de993bcb5 Mon Sep 17 00:00:00 2001 From: cowbra <32939303+cowbra@users.noreply.github.com> Date: Mon, 19 Sep 2022 18:36:56 +0200 Subject: [PATCH 3/5] seance2.3 --- index.js | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/index.js b/index.js index 5976a40..b05ce13 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ function getFilmingLocationsNumber () { const keyCount = Object.keys(filmingLocations).length; return keyCount; } -console.log(`There is ${getFilmingLocationsNumber()} filming locations in Paris`) +//console.log(`There are ${getFilmingLocationsNumber()} filming locations in Paris`) // 📝 TODO: Filming locations sorted by start date, from most recent to oldest. // 1. Implement the function @@ -29,12 +29,12 @@ function sortFilmingLocationsByStartDate (filmArray) { }); } const resultat1 = sortFilmingLocationsByStartDate(filmingLocations); -console.log(resultat1[0].fields.date_debut,resultat1[resultat1.length-1].fields.date_debut) +//console.log(resultat1[0].fields.date_debut,resultat1[resultat1.length-1].fields.date_debut) // 📝 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 (filmArray) { const result= filmArray.map(function(film) { @@ -43,8 +43,8 @@ function getFilmingLocationsNumber2020 (filmArray) { }); return sortFilmingLocationsByStartDate(result) } -console.log(getFilmingLocationsNumber2020(filmingLocations)) -*/ +//console.log(getFilmingLocationsNumber2020(filmingLocations)) + @@ -56,31 +56,23 @@ console.log(getFilmingLocationsNumber2020(filmingLocations)) // '2021': 1234, // } // 2. Log the result - -function getnumberfilmofyear(year) -{ - const filmsOfYears= filmingLocations.map(function(film) { - if(film.fields.annee_tournage == year) - return film; - }); - - const numberfilmsofYear = Object.keys(filmsOfYears).length; - return JSON.parse(year,numberfilmsofYear); -} - - - - -function getFilmingLocationsNumberPerYear () { - let jsonArrayResult = {} - - - - return result; +function countFilmsByYear(){ + + let data = {} + for(let i = 0; i < filmingLocations.length-1; i++) + { + if (filmingLocations[i].fields.annee_tournage in data) + { + data[filmingLocations[i].fields.annee_tournage] += 1 + } + + else data[filmingLocations[i].fields.annee_tournage]=1 + } + return data } -console.log(getnumberfilmofyear(2020)) +console.log(countFilmsByYear()) // 📝 TODO: Number of filming locations by district (arrondissement) // 1. Implement the function, the expected result is an object with From f527ad7fa4854c7b973acc6ae2d560062b7684cd Mon Sep 17 00:00:00 2001 From: cowbra Date: Wed, 28 Sep 2022 21:25:27 +0200 Subject: [PATCH 4/5] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e30b9c..d28fc24 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Manipulate Data with Javascript and NodeJS - +HUGO ## 🌟 Goal > Learning Javascript basics by manipulating arrays, objects, functions etc... From f84e61b1f9e5bd56aaf658ec011051d94e17bfe6 Mon Sep 17 00:00:00 2001 From: cowbra Date: Wed, 28 Sep 2022 21:26:39 +0200 Subject: [PATCH 5/5] update 2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d28fc24..0e30b9c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Manipulate Data with Javascript and NodeJS -HUGO + ## 🌟 Goal > Learning Javascript basics by manipulating arrays, objects, functions etc...