-
-
Notifications
You must be signed in to change notification settings - Fork 282
London -10- Akram-Izedi-Javascript-core-1-coursework-week3 #264
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,15 @@ | |
| - Hint: you can call the temperatureService function from your function | ||
| */ | ||
|
|
||
| function getTemperatureReport(cities) { | ||
| // TODO | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Afsoon this is my review for this week Thank Afsoon |
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,14 @@ | |
| Implement the function below, which will return a new array containing only article titles which will fit. | ||
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
||
| } | ||
|
|
||
| /* | ||
|
|
@@ -14,25 +21,51 @@ function potentialHeadlines(allArticleTitles) { | |
| (you can assume words will always be seperated by a space) | ||
| */ | ||
| function titleWithFewestWords(allArticleTitles) { | ||
| // TODO | ||
| const separateTitleArray = []; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have a think if you really need to create the |
||
| for (const articleTitle of allArticleTitles) { | ||
| allArticleTitles.toString().split(" "); | ||
| separateTitleArray.push(articleTitle) | ||
| } | ||
| let titleWithFewestWords = separateTitleArray.reduce((fewestWords, currentWords) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| 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; | ||
|
|
||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,17 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |
| Functions can help with this! | ||
| */ | ||
| function getAveragePrices(closingPricesForAllStocks) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good attempt! 😄 A few small points:
|
||
| // 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; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one looks good. One point here: |
||
| // 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 | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -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 | ||
| } | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
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: