From d14ac44f431b606361225f7eefc0119941663eb7 Mon Sep 17 00:00:00 2001 From: Stelladelmar Date: Tue, 11 Apr 2023 16:58:30 +0100 Subject: [PATCH 1/3] a a --- .vscode/settings.json | 5 ++++ 2-mandatory/1-weather-report.js | 49 +++++++++++++++++++++----------- 2-mandatory/2-financial-times.js | 2 +- README.md | 4 +-- 4 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..284de991 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "Paulo" + ] +} \ No newline at end of file diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..1fc139b7 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -2,34 +2,51 @@ Imagine we're making a weather app! We have a list of cities that the user wants to track. - We also already have a temperatureService function which will take a city as a parameter and return a temparature. + We also already have a temperatureService function + which will take a city as a parameter and return a + temperature. Implement the function below: - take the array of cities as a parameter - - return an array of strings, which is a statement about the temperature of each city. - For example, "The temperature in London is 10 degrees" - - Hint: you can call the temperatureService function from your function + - return an array of strings, which is a + statement about the temperature of each city. + For example, "The temperature in London is + 10 degrees" + - Hint: you can call the temperatureService + function from your function */ +//temperatureService +//temperature + +//const cities = [ "London", "Paris", "Barcelona", "Dubai", "Mumbai", "São Paulo", "Lagos"]; + function getTemperatureReport(cities) { - // TODO + let result = []; + for (let city of cities) { + let temperature = temperatureService(city); + result.push(`The temperature in ${city} is ${temperature}°C`); +} +return result; } +//console.log(`The temperature in ${"city"} is ${temperature}°C`); +// TODO /* ======= TESTS - DO NOT MODIFY ===== */ function temperatureService(city) { - let temparatureMap = new Map(); - - temparatureMap.set('London', 10); - temparatureMap.set('Paris', 12); - temparatureMap.set('Barcelona', 17); - temparatureMap.set('Dubai', 27); - temparatureMap.set('Mumbai', 29); - temparatureMap.set('São Paulo', 23); - temparatureMap.set('Lagos', 33); - - return temparatureMap.get(city); + let temperatureMap = new Map(); + + temperatureMap.set('London', 10); + temperatureMap.set('Paris', 12); + temperatureMap.set('Barcelona', 17); + temperatureMap.set('Dubai', 27); + temperatureMap.set('Mumbai', 29); + temperatureMap.set('São Paulo', 23); + temperatureMap.set('Lagos', 33); + + return temperatureMap.get(city); } test("should return a temperature report for the user's cities", () => { diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..548623eb 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -11,7 +11,7 @@ function potentialHeadlines(allArticleTitles) { /* The editor of the FT likes short headlines with only a few words! Implement the function below, which returns the title with the fewest words. - (you can assume words will always be seperated by a space) + (you can assume words will always be separated by a space) */ function titleWithFewestWords(allArticleTitles) { // TODO diff --git a/README.md b/README.md index 1ca17aae..5e6acd60 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Like learning a musical instrument, programming requires daily practise. +Like learning a musical instrument, programming requires daily practice. The exercises are split into three folders: `exercises`, `mandatory` and `extra`. All homework in the `exercise` and `mandatory` section **must** be completed for homework by the following lesson. @@ -21,7 +21,7 @@ This is a **private** repository. Please request access from your Teachers, Budd ## Instructions for submission -For your homework, we'll be using [**test driven development**](https://medium.com/@adityaalifnugraha/test-driven-development-tdd-in-a-nutshell-b9e05dfe8adb) to check your answers. Test driven development (or TDD) is the practice of writing tests for your code first, and then write your code to pass those tests. This is a very useful way of writing good quality code and is used in a lot of industries. You don't have to worry about knowing how this works, but if you're curious, engage with a volunteer to find out more! :) +For your homework, we'll be using [**test driven development**](https://medium.com/@adityaalifnugraha/test-driven-development-tdd-in-a-nutshell-b9e05dfe8adb) to check your answers. Test driven development (or TDD) is the practice of writing tests for your code first, and then write your code to pass those tests. This is a very useful way of writing good quality code and is used in a lot of industries. You don't have to worry about knowing how this works, but if you're curious, engage with a volunteer to find out more! : 1. Complete the challenges in each file and save it once you're happy with your changes 2. Run the script to check the results against the tests - all tests should read PASSED if you completed the challenges correctly. If a test reads FAILED, find the associated test to identify which function failed and fix it. From 766462077707f67c922329a2cc6d12b8631ed4bb Mon Sep 17 00:00:00 2001 From: Stelladelmar Date: Wed, 12 Apr 2023 17:20:45 +0100 Subject: [PATCH 2/3] nextAttempt# --- 2-mandatory/1-weather-report.js | 2 +- 2-mandatory/2-financial-times.js | 41 +++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index 1fc139b7..c870607a 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -45,7 +45,7 @@ function temperatureService(city) { temperatureMap.set('Mumbai', 29); temperatureMap.set('São Paulo', 23); temperatureMap.set('Lagos', 33); - + return temperatureMap.get(city); } diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 548623eb..6de9a634 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -1,20 +1,42 @@ /* - Imagine you are working on the Financial Times web site! They have a list of article titles stored in an array. + Imagine you are working on the Financial Times web site! + They have a list of article titles stored in an array. - The home page of the web site has a headline section, which only has space for article titles which are 65 characters or less. - Implement the function below, which will return a new array containing only article titles which will fit. + The home page of the web site has a headline section, + which only has space for article titles which are 65 characters + or less. + Implement the function below, which will return a new array + containing only article titles which will fit. */ +//if length is 65 or more, to include. + function potentialHeadlines(allArticleTitles) { - // TODO -} + const thisArticle = []; + for (const title of allArticleTitles){ + if (title.length <= 65){ + thisArticle.push(title); + } + }return thisArticle; +} //console.log(thisArticle); /* - The editor of the FT likes short headlines with only a few words! - Implement the function below, which returns the title with the fewest words. - (you can assume words will always be separated by a space) + The editor of the FT likes short headlines with + only a few words! + Implement the function below, which returns the + title with the fewest words. + (you can assume words will always be separated + by a space) */ function titleWithFewestWords(allArticleTitles) { - // TODO + // let headlines = ""; + let shortestHeadLine = headlines -1; + for (let shortestHeadLine of allArticleTitles){ + if (shortestHeadLine === "" || shortestHeadLine.length < shortestHeadLine.length){ + shortestHeadLine = + + } +} + } /* @@ -24,6 +46,7 @@ function titleWithFewestWords(allArticleTitles) { */ function headlinesWithNumbers(allArticleTitles) { // TODO + } /* From 651636a2ca0c36afad7dfa3996fc48e5be1f7005 Mon Sep 17 00:00:00 2001 From: Stelladelmar Date: Thu, 13 Apr 2023 01:03:15 +0100 Subject: [PATCH 3/3] Update 2-financial-times.js not finished/done by comparing with others and theories --- 2-mandatory/2-financial-times.js | 53 +++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 6de9a634..49331403 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -29,34 +29,59 @@ function potentialHeadlines(allArticleTitles) { */ function titleWithFewestWords(allArticleTitles) { // let headlines = ""; - let shortestHeadLine = headlines -1; - for (let shortestHeadLine of allArticleTitles){ - if (shortestHeadLine === "" || shortestHeadLine.length < shortestHeadLine.length){ - shortestHeadLine = + //let shortestHeadLine = headlines -1; + for (let headlines of allArticleTitles){ + if (shortestHeadLine === "" || headlines.length < shortestHeadLine.length){ + shortestHeadLine = headlines; } } + return shortestHeadLine; } +//console.log(shortestHeadLine); + -} /* - The editor of the FT has realised that headlines which have numbers in them get more clicks! - Implement the function below to return a new array containing all the headlines which contain a number. - (Hint: remember that you can also loop through the characters of a string if you need to) + The editor of the FT has realised that headlines which + have numbers in them get more clicks! + Implement the function below to return a new array + containing all the headlines which contain a number. + (Hint: remember that you can also loop through the + characters of a string if you need to) */ +//break function headlinesWithNumbers(allArticleTitles) { - // TODO + let articlesContainingNumber = []; + for (const headline of allArticleTitles){ + if (number.has(headline)){ + articlesContainingNumber.push(headline); + break; + } + } + + return articlesContainingNumber; + + } -} /* - The Financial Times wants to understand what the average number of characters in an article title is. - Implement the function below to return this number - rounded to the nearest integer. + The Financial Times wants to understand what the average + number of characters in an article title is. + Implement the function below . +// expect(averageNumberOfCharacters(ARTICLE_TITLES)).toEqual(65); +//to use Math.round(x) */ function averageNumberOfCharacters(allArticleTitles) { - // TODO -} + //let averageCharacterNumber = averageNumberOfCharacters / allArticleTitles.length; + let averageCharacterNumber = 0; + for (let Titles of allArticleTitles){ + averageCharacterNumber = averageCharacterNumber + Titles.length; + } + let ((averageCharacterNumber + allArticleTitles.length) /Titles); +} +//averageNumber; +//not finished yet****** /* ======= List of Articles - DO NOT MODIFY ===== */