Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
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
11 changes: 9 additions & 2 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
- Hint: you can call the temperatureService function from your function
*/

function getTemperatureReport(cities) {
// TODO

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 good to me 👍 2 small notes:

function getTemperatureReport(cities ) {
const statements = [];
for ( const city of cities){
let degrees = temperatureService (city);
let statement = ("The temperature in " + city + " is " + degrees + " degrees");
statements.push(statement);
}
return statements;
}

Choose a reason for hiding this comment

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

Hi Afsoon
I sew you done nice work here with big effort and I want add here you can use .forEach method here kind of short cut with open big chances to know how function it work and make it more fun easy.
check here for more info

this is my review for this week

Thank Afsoon


Expand Down
45 changes: 39 additions & 6 deletions 2-mandatory/2-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
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.

Nice 👍

// TODO
const shortArticleTitles=[ ];
for ( const articleTitle of allArticleTitles) {
if (articleTitle.length <= 65) {
shortArticleTitles.push(articleTitle);
}
}
return shortArticleTitles;

}

/*
Expand All @@ -14,25 +21,51 @@ function potentialHeadlines(allArticleTitles) {
(you can assume words will always be seperated by a space)
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
const separateTitleArray = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Have a think if you really need to create the separateTitleArray. Maybe you can use reduce on the allArticleTitles directly?

for (const articleTitle of allArticleTitles) {
allArticleTitles.toString().split(" ");
separateTitleArray.push(articleTitle)
}
let titleWithFewestWords = separateTitleArray.reduce((fewestWords, currentWords) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This part of the code looks very good - but there's one small problem.
The question is asking you for the title with the fewest words - but here it looks like you're comparing the number of characters: currentWords.length < fewestWords.length
Can you think about how you might fix this?

return currentWords.length < fewestWords.length ? currentWords : fewestWords;
}, separateTitleArray[0]);
return titleWithFewestWords;
}


/*
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 headlinesWithNumbers(allArticleTitles) {
let section = [];

for (const title of allArticleTitles){
for (const character of title){
if ('0123456789'.includes(character)){
section.push(title);
break;
}

}
}
return section;

}
Copy link

Choose a reason for hiding this comment

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

Nice work


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

Choose a reason for hiding this comment

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

Looks good!

// TODO
}
let totalCharacters = 0;
for (const headline of allArticleTitles){
totalCharacters = totalCharacters + headline.length;
}
return Math.round(totalCharacters / allArticleTitles.length);
}




Expand Down
37 changes: 33 additions & 4 deletions 2-mandatory/3-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
Functions can help with this!
*/
function getAveragePrices(closingPricesForAllStocks) {
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! 😄 A few small points:

  • The question is expecting us to use the array which is being passed in as a parameter: closingPricesForAllStocks but it looks like you're using the CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS array instead
  • Spend some time thinking about the best way to name your variables. For example, in the code below you are using a prices variable - but this is really just a single price, so maybe price would be a better name here.

// TODO
let averagePrices = [];
for (const stock of CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS){
let pricesTotal = 0;
for (const prices of stock){
pricesTotal += prices;
}
let averagePrice = Number((pricesTotal / stock.length).toFixed(2));
averagePrices.push(averagePrice);
}

return averagePrices;
}

/*
Expand All @@ -48,7 +58,12 @@ function getAveragePrices(closingPricesForAllStocks) {
The price change value should be rounded to 2 decimal places, and should be a number (not a string)
*/
function getPriceChanges(closingPricesForAllStocks) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This one looks good. One point here:
In this code - stock[4] - stock[0] - what would happen if the arrays we were passing in had more than 5 prices? Or less than 5 prices? Could you change this so it works for any number of prices?

// TODO
const priceChanges = [];
for (const stock of CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS){
let priceChange = Number((stock[4] - stock[0]).toFixed(2));
priceChanges.push(priceChange);
}
return priceChanges
}

/*
Expand All @@ -63,8 +78,22 @@ function getPriceChanges(closingPricesForAllStocks) {
The stock ticker should be capitalised.
The price should be shown with exactly 2 decimal places.
*/
function highestPriceDescriptions(closingPricesForAllStocks, stocks) {
// TODO
function highestPriceDescriptions(closingPricesForAllStocks , stocks) {
const highestPriceReports = [];
for (let i=0 ; i < closingPricesForAllStocks.length ; i++){
let highestPrice = 0

closingPricesForAllStocks[i].forEach(prices => {
if (prices > highestPrice){
highestPrice=prices
}

});

highestPrice = Number(highestPrice)
highestPriceReports.push(`The highest price of ${stocks[i].toUpperCase()} in the last 5 days was ${highestPrice.toFixed(2)}`)
}
return highestPriceReports
}


Expand Down