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

London-10/Mahendra-Balal/JavaScript-core-1/Coursework/Week-3 #265

Open
wants to merge 1 commit 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
9 changes: 8 additions & 1 deletion 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
*/

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.

This looks perfect! Good job 😄

// TODO
const statements = [];
for (let i = 0; i < cities.length; i++) {
const city = cities[i];
const temperature = temperatureService(city);
const statement = `The temperature in ${city} is ${temperature} degrees`;
statements.push(statement);
}
return statements;
}


Expand Down
53 changes: 45 additions & 8 deletions 2-mandatory/2-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,69 @@
Implement the function below, which will return a new array containing only article titles which will fit.
*/
function potentialHeadlines(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 implementation here looks good 👍
I would suggest giving the ARTICLE_TITLES a different name. It may be confusing because there's another variable with the same name on this page.
Can you think of a different name for it?

// TODO
const ARTICLE_TITLES = [];
for (let i = 0; i < allArticleTitles.length; i++) {
if (allArticleTitles[i].length <= 65) {
ARTICLE_TITLES.push(allArticleTitles[i]);
};


}

return ARTICLE_TITLES;
}


/*
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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good attempt. I think there is one small problem with this code.
We want to look for the article with the fewest words. Have a think about what .split("") does in your code.

// TODO
let shortestTitle = "";
let shortestWordCount = Infinity;

for (let i = 0; i < allArticleTitles.length; i++) {
const words = allArticleTitles[i].split("");
const wordCount = words.length;
if (wordCount < shortestWordCount) {
shortestTitle = allArticleTitles[i];
shortestWordCount = wordCount;
}
}
return shortestTitle;
}

/*
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)
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
function findingNumber(str) {
return /[0-9]/.test(str);
}

/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Good job 👍
I like how you used another function to help you solve the problem 😄

function headlinesWithNumbers(allArticleTitles) {
let titleWithNumbers = [];
for (let i = 0; i < allArticleTitles.length; i++) {
if (findingNumber(allArticleTitles[i])) {
titleWithNumbers.push(allArticleTitles[i]);
}
}
return titleWithNumbers;
}
/*
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.
*/
function averageNumberOfCharacters(allArticleTitles) {
// TODO
let totalCharacter = 0;
let totalTitles = allArticleTitles.length;

for (let i = 0; i < totalTitles; i++) {
totalCharacter += allArticleTitles[i].length;
}
return Math.round(totalCharacter / totalTitles);
}


Expand All @@ -49,7 +85,8 @@ const ARTICLE_TITLES = [
"The three questions that dominate investment",
"Brussels urges Chile's incoming president to endorse EU trade deal",
];

// console.log(potentialHeadlines(ARTICLE_TITLES));
potentialHeadlines(ARTICLE_TITLES)
/* ======= TESTS - DO NOT MODIFY ===== */

test("should only return potential headlines", () => {
Expand Down
4 changes: 4 additions & 0 deletions 3-extra/1-radio-stations.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
*/

// `getAllFrequencies` goes here
function getAllFrequencies(allFrequency) {

for ()
}

/**
* Next, let's write a function that gives us only the frequencies that are radio stations.
Expand Down