Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

LND10 | Adrian Ilovan | JS1 Coursework Week3 #262

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
*/

function getTemperatureReport(cities) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! 👍

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
}

Expand Down
46 changes: 40 additions & 6 deletions 2-mandatory/2-financial-times.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
/*
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.
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good 👍
For extra practice, can you try re-writing this using the filter array method?

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!
Implement the function below, which returns the title with the fewest words.
(you can assume words will always be seperated by a space)
*/
function titleWithFewestWords(allArticleTitles) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good solution!

// 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;
}

/*
Expand All @@ -24,6 +44,13 @@ function titleWithFewestWords(allArticleTitles) {
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next few exercises look good as well!
I would recommend you practice all of these using array methods now 😄

function headlinesWithNumbers(allArticleTitles) {
// TODO
let arrayOfNumbers = [];
for (article of allArticleTitles) {
if (/\d/.test(article)) {
arrayOfNumbers.push(article);
}
}
return arrayOfNumbers;
}

/*
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}