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 } diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..8c56d66b 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -1,12 +1,23 @@ /* - 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 -} + let headline = []; + for (let article of allArticleTitles) { + if (article.length <= 65) { + headline.push(article); + } + } + return headline + } + /* The editor of the FT likes short headlines with only a few words! @@ -14,7 +25,16 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles) { - // TODO + 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; } /* @@ -24,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; } /* @@ -32,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", 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" } }