-
-
Notifications
You must be signed in to change notification settings - Fork 279
Glasgow Class 6 Melese Berehannu JavaScript-Core-1-Coursework-Week3 #239
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 |
|---|---|---|
|
|
@@ -6,6 +6,15 @@ | |
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
| // TODO | ||
| const newArray = []; | ||
| for (let articleTitle of allArticleTitles){ | ||
| if (articleTitle.length <= 65){ | ||
| newArray.push(articleTitle) | ||
| } | ||
| } | ||
| return newArray; | ||
|
Comment on lines
+9
to
+15
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. Good! Although it's good to try and make variable names reflect what they are doing. For example here, a better name than 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 another good function Melese. Easy for someone else to follow. |
||
|
|
||
|
|
||
| } | ||
|
|
||
| /* | ||
|
|
@@ -15,6 +24,16 @@ function potentialHeadlines(allArticleTitles) { | |
| */ | ||
| function titleWithFewestWords(allArticleTitles) { | ||
| // TODO | ||
| const title = []; | ||
| let titleWithFewestWord = allArticleTitles[0].length; | ||
| for (let fewWord of allArticleTitles){ | ||
| if (fewWord.split(' ').length < titleWithFewestWord){ | ||
| titleWithFewestWord = fewWord.split(' ').length | ||
| title.push(fewWord) | ||
| }else{ | ||
| titleWithFewestWord = titleWithFewestWord; | ||
|
Comment on lines
+33
to
+34
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. I don't think we need this else statement here as it's not doing anything. |
||
| } | ||
| }return title[title.length-1]; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -24,6 +43,15 @@ function titleWithFewestWords(allArticleTitles) { | |
| */ | ||
| function headlinesWithNumbers(allArticleTitles) { | ||
| // TODO | ||
| const headlinesWithNumber =[]; | ||
| for (let article of allArticleTitles){ | ||
| for (let char of article){ | ||
| if(char.match(/[0123456789]/g)){ | ||
| headlinesWithNumber.push(article);break; | ||
| } | ||
| } | ||
| }return headlinesWithNumber; | ||
|
|
||
|
Comment on lines
+46
to
+54
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! |
||
| } | ||
|
|
||
| /* | ||
|
|
@@ -32,6 +60,11 @@ function headlinesWithNumbers(allArticleTitles) { | |
| */ | ||
| function averageNumberOfCharacters(allArticleTitles) { | ||
| // TODO | ||
| let averageNumberOfCharacter = 0; | ||
| for (let articleTitle of allArticleTitles){ | ||
| averageNumberOfCharacter = averageNumberOfCharacter + articleTitle.length | ||
| } | ||
| return Math.round((averageNumberOfCharacter/allArticleTitles.length).toFixed(0)) | ||
| } | ||
|
Comment on lines
+63
to
68
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. 👏 |
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,15 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |
| */ | ||
| function getAveragePrices(closingPricesForAllStocks) { | ||
| // TODO | ||
| } | ||
| const averagePrices = []; | ||
|
|
||
| for (let closingPriceForStock of closingPricesForAllStocks){ | ||
| averagePrices.push(Number(((closingPriceForStock.reduce((a,b) => a + b, 0))/(closingPriceForStock.length)).toFixed(2))) | ||
| } | ||
| return averagePrices; | ||
|
|
||
| } | ||
|
|
||
|
Comment on lines
+38
to
+46
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 use of reduce 👌 |
||
|
|
||
| /* | ||
| We also want to see what the change in price is from the first day to the last day for each stock. | ||
|
|
@@ -49,6 +57,11 @@ function getAveragePrices(closingPricesForAllStocks) { | |
| */ | ||
| function getPriceChanges(closingPricesForAllStocks) { | ||
| // TODO | ||
| const priceChanges = []; | ||
| for (let closingPriceForStock of closingPricesForAllStocks){ | ||
| priceChanges.push(Number((closingPriceForStock[closingPriceForStock.length-1]-closingPriceForStock[0]).toFixed(2))) | ||
| } | ||
| return priceChanges; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -64,7 +77,12 @@ function getPriceChanges(closingPricesForAllStocks) { | |
| The price should be shown with exactly 2 decimal places. | ||
| */ | ||
| function highestPriceDescriptions(closingPricesForAllStocks, stocks) { | ||
|
|
||
| // TODO | ||
| const priceDescription = []; | ||
| for (let i = 0; i < closingPricesForAllStocks.length; i++){ | ||
| priceDescription.push(`The highest price of ${stocks[i].toUpperCase()} in the last 5 days was ${(((closingPricesForAllStocks[i]).sort(function(a,b){return a - b})[closingPricesForAllStocks[i].length-1]).toFixed(2))}`) } | ||
| return priceDescription; | ||
|
Comment on lines
+82
to
+85
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 great. The only suggestion I would make is to format your code so that it's easier to read. I think we are going to talk about this in class tomorrow :) |
||
| } | ||
|
|
||
|
|
||
|
|
||
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.
👏
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.
I like how you have simplified your code Melese. I found it easier to understand.