From 08840fae10880ebb629f6f62cf34d22ea4e2e9b0 Mon Sep 17 00:00:00 2001 From: AdrianIlovan <62564810+AdrianIlovan@users.noreply.github.com> Date: Mon, 6 Mar 2023 23:22:45 +0000 Subject: [PATCH 1/4] only first task finished --- 2-mandatory/1-weather-report.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..60f2631a 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -12,6 +12,16 @@ */ function getTemperatureReport(cities) { + const reports=[] + + for (const city of cities) { + const temperature = temperatureService(city); + const report = `The temperature in ${city} is ${temperature} degrees`; + reports.push(report); + } + + return reports; + // TODO } From 0ef448f4d0399577d705638b63dc7d43101d4778 Mon Sep 17 00:00:00 2001 From: AdrianIlovan <62564810+AdrianIlovan@users.noreply.github.com> Date: Tue, 7 Mar 2023 19:13:35 +0000 Subject: [PATCH 2/4] First part of 2-Financial-times done --- 2-mandatory/2-financial-times.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..320f5d01 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -1,11 +1,20 @@ /* - 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. */ function potentialHeadlines(allArticleTitles) { - // TODO + const headlines = []; + for (let i = 0; i < allArticleTitles.length; i++) { + if (allArticleTitles[i].length <= 65) { + headlines.push(allArticleTitles[1]); + } + } + return headlines; } /* From 7999e431303f92b1894c3a44a2dca25f9e97d459 Mon Sep 17 00:00:00 2001 From: AdrianIlovan Date: Fri, 10 Mar 2023 17:30:29 +0000 Subject: [PATCH 3/4] Financial Mandatory 1st exercise done --- 2-mandatory/2-financial-times.js | 15 ++++++++------- README.md | 2 +- package.json | 3 ++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 320f5d01..f572f5c2 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -7,15 +7,17 @@ Implement the function below, which will return a new array containing only article titles which will fit. */ + function potentialHeadlines(allArticleTitles) { - const headlines = []; - for (let i = 0; i < allArticleTitles.length; i++) { - if (allArticleTitles[i].length <= 65) { - headlines.push(allArticleTitles[1]); + let headline = []; + for (let article of allArticleTitles) { + if (article.length <= 65) { + headline.push(article); } } - return headlines; -} + return headline + } + /* The editor of the FT likes short headlines with only a few words! @@ -23,7 +25,6 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles) { - // TODO } /* diff --git a/README.md b/README.md index 1ca17aae..502f7a73 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ This is a **private** repository. Please request access from your Teachers, Budd ## Testing your work -- Each of the *.js files in the `1-exercises` folder can be run from the terminal using the `node` command with the path to the file. For example, `node 1-exercises/A-undefined/exercise.js` can be run from the root of the project. +- Each of the *.js files in the `1-exercises` folder can be run from the terminal using the `node` command with the path to the file. For example, `` can be run from the root of the project. - To run the tests in the `2-mandatory` folder, run `npm run test` from the root of the project (after having run `npm install` once before). - To run the tests in the `3-extra` folder, run `npm run extra-tests` from the root of the project (after having run `npm install` once before). diff --git a/package.json b/package.json index dc4e9ace..6bc5a21c 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ }, "homepage": "https://github.com/CodeYourFuture/JavaScript-Core-1-Coursework-Week3#readme", "devDependencies": { - "jest": "^26.6.3" + "jest": "^26.6.3", + "prettier": "2.8.4" } } From 532d19b85f1c9208e71f803f560ca4b53b320b77 Mon Sep 17 00:00:00 2001 From: AdrianIlovan Date: Fri, 10 Mar 2023 18:43:54 +0000 Subject: [PATCH 4/4] 2/3 exercises completed --- 2-mandatory/2-financial-times.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index f572f5c2..8c56d66b 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -25,6 +25,16 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles) { + let numberOfWords; + let smallerTitle; + for (let headlineTitle of allArticleTitles) { + let titleSplit = headlineTitle.split(" ").length; + if (titleSplit < numberOfWords || numberOfWords === undefined) { + numberOfWords = titleSplit; + smallerTitle = headlineTitle; + } + } + return smallerTitle; } /* @@ -34,6 +44,13 @@ function titleWithFewestWords(allArticleTitles) { */ function headlinesWithNumbers(allArticleTitles) { // TODO + let arrayOfNumbers = []; + for (article of allArticleTitles) { + if (/\d/.test(article)) { + arrayOfNumbers.push(article); + } + } + return arrayOfNumbers; } /* @@ -42,10 +59,17 @@ function headlinesWithNumbers(allArticleTitles) { */ function averageNumberOfCharacters(allArticleTitles) { // TODO + let totalCharacters = 0; + for (let article of allArticleTitles) { + totalCharacters += article.length; + } + return Math.round(totalCharacters / allArticleTitles.length); } + + /* ======= List of Articles - DO NOT MODIFY ===== */ const ARTICLE_TITLES = [ "Streaming wars drive media groups to spend more than $100bn on new content",