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- Delnia Alipour-JavaScript/Core1- Week 3 #223
Open
DelniaAlipour
wants to merge
4
commits into
CodeYourFuture:main
Choose a base branch
from
DelniaAlipour: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
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 |
|---|---|---|
|
|
@@ -6,32 +6,61 @@ | |
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
| // TODO | ||
| const fitArticleTitles=[]; | ||
| for (let i=0; i<allArticleTitles.length; i++){ | ||
| if(allArticleTitles[i].length<=65){ | ||
| fitArticleTitles.push(allArticleTitles[i]); | ||
| } | ||
| } | ||
| return fitArticleTitles; | ||
| } | ||
|
|
||
| /* | ||
| 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) { | ||
| // TODO | ||
| } | ||
|
|
||
| let fewestWords=allArticleTitles[0]; | ||
| for( let i =1; i<allArticleTitles.length; i++){ | ||
| if(fewestWords.length>allArticleTitles[i].length){ | ||
| fewestWords=allArticleTitles[i]; | ||
| } | ||
| } | ||
| return fewestWords; | ||
| } | ||
| // function getWordsCount(allArticleTitles){ | ||
| // return allArticleTitles.split(" ").length; | ||
| // } | ||
| /* | ||
| The editor of the FT has realised that headlines which have numbers in them get more clicks! | ||
| The editor of the FT has realized 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 | ||
| const containNumbers=[]; | ||
| for(let i =0; i<allArticleTitles.length; i++){ | ||
| let isContainNum= /[0-9]/.test(allArticleTitles[i]); | ||
|
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. Interesting use of a regular expression here! |
||
| if(isContainNum){ | ||
| containNumbers.push(allArticleTitles[i]); | ||
| } | ||
| } | ||
| return containNumbers; | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| 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 numOfChar=0; | ||
| for(let i =0; i<allArticleTitles.length; i++){ | ||
| numOfChar += allArticleTitles[i].length; | ||
| } | ||
| let average= numOfChar / 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 |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| /* | ||
| THESE EXERCISES ARE QUITE HARD. JUST DO YOUR BEST, AND COME WITH QUESTIONS IF YOU GET STUCK :) | ||
|
|
||
| Imagine we a working for a finance company. Below we have: | ||
| Imagine we are working for a finance company. Below we have: | ||
| - an array of stock tickers | ||
| - an array of arrays containing the closing price for each stock in each of the last 5 days. | ||
| For example, CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS[2] contains the prices for the last 5 days for STOCKS[2] (which is amzn) | ||
|
|
@@ -35,6 +35,19 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |
| */ | ||
| function getAveragePrices(closingPricesForAllStocks) { | ||
| // TODO | ||
| const averagePrice=[]; | ||
| let sum=0; | ||
| let average=0 | ||
| for(let i =0; i<closingPricesForAllStocks.length; i++){ | ||
| for( let j=0; j<closingPricesForAllStocks[i].length;j++){ | ||
| sum +=closingPricesForAllStocks[i][j]; | ||
| } | ||
| average=sum / 5; | ||
| averagePrice.push(Math.round(average*100)/100); | ||
| sum=0; | ||
|
|
||
| } | ||
| return averagePrice; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -48,8 +61,18 @@ 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 | ||
| } | ||
| const priceChanged=[]; | ||
| let change=0; | ||
| let average=0 | ||
| for(let i =0; i<closingPricesForAllStocks.length; i++){ | ||
| let j=closingPricesForAllStocks[i][closingPricesForAllStocks[i].length-1]; | ||
|
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. It's usually better to use full descriptions in variable names - variables like |
||
| let k= closingPricesForAllStocks[i][0]; | ||
| change =j-k; | ||
| priceChanged.push(Math.round(change*100)/100); | ||
| change=0; | ||
| } | ||
| return priceChanged; | ||
| } | ||
|
|
||
| /* | ||
| As part of a financial report, we want to see what the highest price was for each stock in the last 5 days. | ||
|
|
@@ -64,7 +87,20 @@ function getPriceChanges(closingPricesForAllStocks) { | |
| The price should be shown with exactly 2 decimal places. | ||
| */ | ||
| function highestPriceDescriptions(closingPricesForAllStocks, stocks) { | ||
| // TODO | ||
| const hightestPrice=[]; | ||
| let maxPrice=0; | ||
| for(let k=0; k<stocks.length;){ | ||
| for(let i=0; i< closingPricesForAllStocks.length; i++){ | ||
|
|
||
| maxPrice=Math.max(...closingPricesForAllStocks[i]); | ||
| hightestPrice.push(`The highest price of ${stocks[k].toUpperCase()} in the last 5 days was ${maxPrice.toFixed(2)}`) | ||
| maxPrice=0; | ||
| k++; | ||
|
|
||
| } | ||
|
|
||
| return hightestPrice; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
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
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.
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.
ahas the default value for a variable when no assignment has taken place, which isundefined.