-
-
Notifications
You must be signed in to change notification settings - Fork 279
London 10 Maksim Lukianenko JavaScript-Core-1-Coursework-Week3 #218
base: main
Are you sure you want to change the base?
Changes from all commits
e9ff877
d42c6ff
4325719
5f9009a
ccc8438
37b5313
7df0dd1
b8f50c5
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,15 +6,26 @@ | |
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
| // TODO | ||
| const headTitle = allArticleTitles.filter(title => title.length < 65); | ||
|
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 nice implementation! |
||
| return headTitle; | ||
| } | ||
|
|
||
| /* | ||
| 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 shortestTitle = allArticleTitles[0]; | ||
|
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 looks great 😄 |
||
|
|
||
| for (let i = 0; i < allArticleTitles.length; i++) { | ||
| const currentTitle = allArticleTitles[i]; | ||
| if (currentTitle.length < shortestTitle.length) { | ||
| shortestTitle = currentTitle | ||
| } | ||
| } | ||
| return shortestTitle; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -24,6 +35,7 @@ function titleWithFewestWords(allArticleTitles) { | |
| */ | ||
| function headlinesWithNumbers(allArticleTitles) { | ||
| // TODO | ||
| return allArticleTitles.filter(title => /\d/.test(title)); | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -32,6 +44,9 @@ function headlinesWithNumbers(allArticleTitles) { | |
| */ | ||
| function averageNumberOfCharacters(allArticleTitles) { | ||
| // TODO | ||
| const articleSum = allArticleTitles.reduce((acc, val) => acc + val.length, 0); | ||
|
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 use of |
||
| return Math.round(articleSum / allArticleTitles.length) | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,14 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ | |
| */ | ||
| function getAveragePrices(closingPricesForAllStocks) { | ||
| // TODO | ||
| let currentStock = []; | ||
|
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 looks good 😄 |
||
| for (let i = 0; i < closingPricesForAllStocks.length; i++) { | ||
| const numberOfStocks = closingPricesForAllStocks[i].length; | ||
| const sumOfCurrentStock = closingPricesForAllStocks[i].reduce((accumulator, currentValue) => accumulator + currentValue, 0); | ||
| const roundedStock = Math.round((sumOfCurrentStock / numberOfStocks) * 100) / 100; | ||
| currentStock.push(roundedStock); | ||
| } | ||
| return currentStock; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -49,6 +57,17 @@ function getAveragePrices(closingPricesForAllStocks) { | |
| */ | ||
| function getPriceChanges(closingPricesForAllStocks) { | ||
| // TODO | ||
| let closingPrices = []; | ||
|
|
||
| for (let i = 0; i < closingPricesForAllStocks.length; i++) { | ||
| const numberOfPrices = closingPricesForAllStocks[i].length - 1; | ||
| const firstDay = closingPricesForAllStocks[i].at(0); | ||
|
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. It's also possible here to use bracket notation twice. For example, |
||
| const lastDay = closingPricesForAllStocks[i].at(numberOfPrices); | ||
| const priceChange = Math.round((lastDay - firstDay) * 100) / 100; | ||
|
|
||
| closingPrices.push(priceChange); | ||
| } | ||
| return closingPrices; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -65,6 +84,17 @@ function getPriceChanges(closingPricesForAllStocks) { | |
| */ | ||
| function highestPriceDescriptions(closingPricesForAllStocks, stocks) { | ||
| // TODO | ||
| let allHighestPrices = []; | ||
| for (let i = 0; i < closingPricesForAllStocks.length; i++) { | ||
| const stockName = stocks[i].toUpperCase(); | ||
| const stockPrices = closingPricesForAllStocks[i]; | ||
| const highestPrice = Math.max(...stockPrices).toFixed(2); | ||
|
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 use of |
||
|
|
||
| allHighestPrices.push(`The highest price of ${stockName} in the last 5 days was ${highestPrice}`) | ||
|
|
||
| } | ||
|
|
||
| return allHighestPrices; | ||
| } | ||
|
|
||
|
|
||
|
|
||
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.
Very nice work 👍