This repository was archived by the owner on Jan 14, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 279
Glasgow 6 - Haroun- JS Core 1 Week 3 #230
Open
HarounAlarabi
wants to merge
3
commits into
CodeYourFuture:main
Choose a base branch
from
HarounAlarabi:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
| let titles=[]; | ||
| for (let i=0; i<allArticleTitles.length; i++) { | ||
| if (allArticleTitles[i].length <= 65) { | ||
| titles.push (allArticleTitles[i]); | ||
| } | ||
| // TODO | ||
| } | ||
| return titles; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -15,23 +22,51 @@ function potentialHeadlines(allArticleTitles) { | |
| */ | ||
| function titleWithFewestWords(allArticleTitles) { | ||
| // TODO | ||
| let fewestWords =Infinity; | ||
| let title=''; | ||
| for(let i=0; i < allArticleTitles.length; i++){ | ||
| let words = allArticleTitles[i].split(" "); | ||
| if(words.length < fewestWords){ | ||
| fewestWords = words.length; | ||
| title = allArticleTitles[i]; | ||
| } | ||
| } | ||
| return title; | ||
| } | ||
|
|
||
| /* | ||
| 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 | ||
| } | ||
| let headlines = []; | ||
| for (let i = 0; i < allArticleTitles.length; i++) { | ||
| if (/\d/.test(allArticleTitles[i])) { | ||
| headlines.push(allArticleTitles[i]); | ||
| } | ||
| } | ||
| return headlines; | ||
| } | ||
|
|
||
|
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. Great using /\d/ .test |
||
|
|
||
|
|
||
|
|
||
|
|
||
| /* | ||
| 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 totalChars = 0; | ||
| for(let i=0 ; i < allArticleTitles.length; i++){ | ||
| totalChars += allArticleTitles[i].length | ||
| } | ||
|
|
||
| let average = totalChars / allArticleTitles.length; | ||
| return Math.round(average); | ||
| } | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |
| We want to understand what the average price over the last 5 days for each stock is. | ||
| Implement the below function, which | ||
| - Takes this CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS array as input (remember, it's an array of arrays) | ||
| - Returns an array containing the average price over the last 5 days for each stock. | ||
| - Returns an array containing the average price over the last 5 days for each stock. | ||
| For example, the first element of the resulting array should contain Apple’s (aapl) average stock price for the last 5 days. | ||
| The second element should be Microsoft's (msft) average price, and so on. | ||
| The average value should be rounded to 2 decimal places, and should be a number (not a string) | ||
|
|
@@ -34,8 +34,24 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |
| Functions can help with this! | ||
| */ | ||
| function getAveragePrices(closingPricesForAllStocks) { | ||
| // TODO | ||
|
|
||
| let days = 5; | ||
| let averagePrice = []; | ||
| for (let i = 0; i < closingPricesForAllStocks.length; i++) { | ||
| let total =0; | ||
| for (let j = 0; j < days; j++) { | ||
| total += closingPricesForAllStocks[i][j]; | ||
| } | ||
|
|
||
| let avg = total / days; | ||
| avg = Math.round(avg * 100) / 100; | ||
| averagePrice.push(avg); | ||
| } | ||
| return averagePrice; | ||
|
|
||
| } | ||
| // TODO | ||
|
|
||
|
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. same here |
||
|
|
||
| /* | ||
| We also want to see what the change in price is from the first day to the last day for each stock. | ||
|
|
@@ -48,9 +64,17 @@ 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) { | ||
| // TODO | ||
| let days = 5; | ||
| let priceChanges = []; | ||
| for (let i = 0; i < closingPricesForAllStocks.length; i++) { | ||
| let priceChange = closingPricesForAllStocks[i][days - 1] - closingPricesForAllStocks[i][0]; | ||
| priceChange = Math.round(priceChange * 100) / 100; | ||
| priceChanges.push(priceChange); | ||
| } | ||
| return priceChanges; | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| As part of a financial report, we want to see what the highest price was for each stock in the last 5 days. | ||
| Implement the below function, which | ||
|
|
@@ -64,6 +88,22 @@ function getPriceChanges(closingPricesForAllStocks) { | |
| The price should be shown with exactly 2 decimal places. | ||
| */ | ||
| function highestPriceDescriptions(closingPricesForAllStocks, stocks) { | ||
| let descriptions = []; | ||
| for (let i = 0; i < closingPricesForAllStocks.length; i++) { | ||
| let highest = Math.max(...closingPricesForAllStocks[i]); | ||
| let stockTicker = stocks[i].toUpperCase(); | ||
| let description = `The highest price of ${stockTicker} in the last 5 days was ${highest.toFixed(2)}`; | ||
| descriptions.push(description); | ||
|
|
||
|
|
||
| } | ||
| return descriptions; | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| // TODO | ||
|
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. WELL DONE! |
||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
You did well! You must remove // TO DO next time